GithubHelp home page GithubHelp logo

gruntjs / grunt-contrib-requirejs Goto Github PK

View Code? Open in Web Editor NEW
504.0 504.0 105.0 67 KB

Optimize RequireJS projects using r.js.

Home Page: http://gruntjs.com/

License: MIT License

JavaScript 100.00%

grunt-contrib-requirejs's People

Contributors

greggman avatar iammerrick avatar jamesplease avatar jgable avatar juhq avatar shama avatar shinnn avatar sindresorhus avatar skoschnicke avatar timsnadden avatar tmacdonald avatar vladikoff avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-contrib-requirejs's Issues

Exits with code 0 if file not found.

I'm not sure if the issue is in the module, Grunt or Node itself, but there it is anyway.
When i'm combining js files and one of the files is not found the process exists with error code 0, and thus my CI server thinks it has built successfully.
The ouput:

Tracing dependencies for: main
Error: ENOENT, no such file or directory '***\appv2\js\pluginsX.js'
In module tree:
    main
      app

Error: ENOENT, no such file or directory '***\appv2\js\pluginsX.js'
In module tree:
    main
      app

    at Object.fs.openSync (fs.js:427:18)

Grunt task is configured like this:

        requirejs: {
            combine: {
                options: {
                    name: "main",
                    out: "appv2/app.combined.js",
                    optimize: "none",
                    excludeShallow: ["jquery"],
                    mainConfigFile: "appv2/main.js"
                }
            }

I'm running node v0.10.5 for Windows, grunt v0.4.1, grunt-contrib-requirejs v0.4.1

Update for compatibility with grunt 0.4.0rc5

I need someone to help update this plugin to work with grunt 0.4.0rc5.

I had to revert the whole file src-dest mappings implicit iteration abstraction per gruntjs/grunt#606, and once again, multi tasks have to iterate over this.files manually. In addition, there's a new this.filesSrc array that contains a reduced, uniqued set of all matched src files in case the task is read-only and only cares about source files.

See:

Notes:

  • A user may specify a new option nonull in addition to src to tell grunt to keep patterns or filepaths that don't actually match files. Because of this, the task shouldn't explode if a nonexistent src filepath is encountered. I handle this in the grunt-contrib-concat by warning if not grunt.file.exists but not failing the task.

Guidelines for updating / publishing this plugin:

  • Change this project's version number to one ending in "rc5" so that it's clearer that it works with grunt 0.4.0rc5. If the existing version number doesn't end in an "a" or "rc" increment the patch version. Eg, jshint went from 0.1.0 -> 0.1.1rc5
  • Ensure grunt 0.4.0rc5-compatible plugins are specified in package.json devDependencies like this (grunt-contrib-internal can be "*")
  • Update the CHANGELOG like this
  • Regenerate the README.md file via grunt.
  • Delete node_modules, run npm cache clean and re-run npm install to test.
  • Publish to npm using --tag=master (not latest)

Already have a build.js file

If I already have a build.js file, is it possible to point to that file as the configuration rather than setting it up in the Gruntfile. Currently I'm using a shell operation and simply doing -o.

minimized JS exported with MIME type text/octet

Running grunt requirejs on my mac seemed to build fine, but the file output after doing a file --mime app.jswas application/octet-stream; charset=binary. Problem is that my GoLang web server interprets this as text/html for some reason.

I can get my server to force the mimetype, but im thinking either r.js or something inbetween could be the culprit.

Grunt: 0.4.2
Node: 0.10.24
RequireJS: 2.1.9
MacOSX: 10.9.2

Add support for specifying an r.js version

It'd be nice to support specifying or providing a version of RequireJS to use when optimizing a project.

Maybe if the project that's being built has specified and installed its own requirejs dependency, prefer that over the one specified in the contrib task?

r.js cache causing errors when multiple requirejs tasks execute serially

We've got two requirejs tasks that we run serially. ex:

grunt requirejs:www requirejs:touch

Their configs are similar, they operate within the same dir, but build a separate set of modules. When running them serially, I get the following error:

Running "requirejs:touch" (requirejs) task
>> Tracing dependencies for: touch.store
>> TypeError: Cannot read property 'override' of undefined
>>     at
>> ./node_modules/requirejs/bin/r.js:23253:63

However, if I run them separately, e.g. grunt requirejs:www && grunt requirejs:touch they work as expected.

Digging in, I found that r.js keeps a cache _buildPathToModuleIndex. When run serially, the second task executes with this cache full from the first task. I didn't have time to fully uncover why it was problematic. I found that I was able to work around the problem by adding:

{
  "_buildPathToModuleIndex": {}
}

to the second task's configuration. This essentially wipes the cache for the second task.

Dynamically generating config object causes wrong directory path to be searched

Hi,

I'm dynamically generating my requirejs task using grunt.config.set. But when I run the task after I've set the config it tries to load my modules from the wrong path and thus errors.

The custom task I'm writing is as follows...

    grunt.registerTask('get-components', 'Parse each HTML file for components', function() {
        var pages = grunt.file.expand('./*.html'),
            config = {
                compile: {
                    options: {
                        baseUrl: './',
                        dir: './release/',
                        paths: {
                            jquery: 'libs/jquery'
                        },
                        fileExclusionRegExp: /^\.|node_modules|Gruntfile|\.md|package.json/,
                        optimize: 'none'
                    }
                }
            };

        pages = pages.map(function(page) {
            var content = grunt.file.read(page),
                pattern = /data-component="([^"]+)"/gmi;

            content = content.match(pattern).map(function(module) {
                return 'libs/' + module.split('"')[1] + '/component';
            });

            return {
                name: 'bootstrap-' + /\.\/([^.]+)/.exec(page)[1],
                include: content
            };
        });

        config.compile.options.modules = pages

        grunt.config.set('requirejs', config);
        console.log(grunt.config.get('requirejs').compile.options.modules);
        grunt.task.run('requirejs');
    });

The config object I'm constructing and setting onto the requirejs task looks like this...

{ compile: 
   { options: 
      { baseUrl: './',
        dir: './release/',
        paths: { jquery: 'libs/jquery' },
        fileExclusionRegExp: /^\.|node_modules|Gruntfile|\.md|package.json/,
        optimize: 'none',
        modules: [ { name: 'bootstrap-about', include: [ 'libs/world/component' ] },
                           { name: 'bootstrap-index', include: [ 'libs/hello/component', 'libs/world/component' ] } 
        ]
       }
     }
   }

The terminal stdout I'm getting back is...

Running "requirejs:compile" (requirejs) task
Verifying property requirejs.compile exists in config...OK
File: [no files]
Options: logLevel=0, done=undefined, baseUrl="./", dir="./release/", paths={"jquery":"libs/jquery"}, fileExclusionRegExp={}, optimize="none", modules=[{"name":"bootstrap-about","include":["libs/world/component"]},{"name":"bootstrap-index","include":["libs/hello/component","libs/world/component"]}]
>> Tracing dependencies for: bootstrap-about
[Error: Error: ENOENT, no such file or directory 'path-to-my-app/release/libs/world/component.js'
    at Object.fs.openSync (fs.js:427:18)
]

...as you can see it's trying to find my modules within the /release/ directory, but that is wrong and I'm not sure why it's inserting the /release/ folder inside that path?

It should instead just point to path-to-my-app/libs/world/component.js and not path-to-my-app/release/libs/world/component.js

Any ideas on how I can fix this issue?

Thanks!

Extend options, not replace all?

I have a require.config({paths:{ โ€ฆ }}); in my main app file with a number of items that I'd rather not have to duplicate in my gruntfile.

This is how I would imagine it would look:

requirejs: {
    "merge app and views": {
        options: {
            extendPaths: {
                newPath: "src/something-new",
                replacePath: "src/production-version"
            },
            baseUrl: "src/",
            name: "init",
            almond: true,
            out: "bin/production.js"
        }
    }
},

Or we could make them all extend by default and add in "replace" options. That might break backwards-compatibility[?], so I'll leave that brainstorm to you guys.

I've made a request to the RequireJS team to implement a nicer API for this (requirejs/requirejs#968), but the following [hack'ish] code will work in the meantime:

$.extend( requirejs.s.contexts._.config.paths, {replacePath:"something/else"} );

Issue with using a JSON RequireJS config file.

The task doesn't work with a typical RequireJS config file, which may look like:

({
    appDir: 'src',
    name: 'application',
    out: 'bin/built.js'
})

This is because the config is passed to RequireJS as the mainConfigFile property rather than as the config object itself.

To get around this issue, you have to make it an extension to the config i.e

require.config({
    appDir: 'src',
    name: 'application',
    out: 'bin/built.js'
});

However, this doesn't work with the command line r.js:
node r.js -o app.build.js
> Unexpected token ;

Would it be possible to have the task parse a file in the first format and use it as the main require js config file?

Preserving license comments for sourcemaps

It looks like all comments, including comments that are marked with @license or @preserve, are removed. According to the requirejs (and uglify) documentation that shouldn't be the case by default.

We're using the following grunt config:

requirejs: {
  compile: {
    options: {
      baseUrl: 'public/js/app'
      mainConfigFile: 'public/js/app/main.js'
      name: 'main'
      out: 'public/js/app/main.js'
      optimize: 'uglify2'
      generateSourceMaps: true
      preserveLicenseComments: false
    }
  }
}

I've also tried adding explicit options for uglify2 to these settings and updated require.js & r.js to the newest versions but that didn't help. Any thoughts?

Loading "requirejs.js" tasks... SyntaxError: Unexpected token .

Hi!

When running the grunt-contrib-requirejs task locally everything works fine.

When running it on the build server I get the following error:

[02:59:26]:  [1mRegistering "grunt-contrib-requirejs" local Npm module tasks. [22m
[02:59:26]: Reading /root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt-contrib-requirejs/package.json... [32mOK [39m
[02:59:26]: Parsing /root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt-contrib-requirejs/package.json... [32mOK [39m
[02:59:26]: /root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:1
[02:59:26]: (function (exports, require, module, __filename, __dirname) { ../requirejs/bin
[02:59:26]: Loading "requirejs.js" tasks... [31mERROR [39m
[02:59:26]:  [31m>>  [39mSyntaxError: Unexpected token . [31m
[02:59:26]: >>  [39m    at Module._compile (module.js:439:25) [31m
[02:59:26]: >>  [39m    at Object.Module._extensions..js (module.js:474:10) [31m
[02:59:26]: >>  [39m    at Module.load (module.js:356:32) [31m
[02:59:26]: >>  [39m    at Function.Module._load (module.js:312:12) [31m
[02:59:26]: >>  [39m    at Module.require (module.js:364:17) [31m
[02:59:26]: >>  [39m    at require (module.js:380:17) [31m
[02:59:26]: >>  [39m    at Object.module.exports (/root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt-contrib-requirejs/tasks/requirejs.js:12:19) [31m
[02:59:26]: >>  [39m    at loadTask (/root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt/lib/grunt/task.js:312:10) [31m
[02:59:26]: >>  [39m    at /root/BuildAgent/work/657e5aa6e9b0e6ef/node_modules/grunt/lib/grunt/task.js:348:7 [31m
[02:59:26]: >>  [39m    at Array.forEach (native)

Node version: v0.10.21
Grunt-contrib-requirejs: v0.4.1
Grunt-cli: v0.1.9
Grunt: v0.4.1

UPDATE:
node_modules have been added to the repository. I do run npm install before build, but nothing gets installed.

Will be grateful for any hints.

Thanks!

External Build File?

Is it possible to point the config to to an external build.js rather than place it all within the Gruntfile? Similar to how grunt-contrib-compass can be pointed to a config.rb file.

Thanks,
Pat

Paths fallback not supported in optimizer?

I am running the Yeoman Beta 7, having installed require.js using the Webapp scaffolding. I am currently having build issues trying to build using Grunt. This has been tested for both Windows and Mac using Beta 7 and the same problem happens on both.

I have updated the require.config function:

require.config({
    paths: {
        jquery: [
            // jQuery Fallback - http://requirejs.org/docs/api.html#pathsfallbacks
            '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min',
            // If the CDN location fails, load from this location
            '../bower_components/jquery/jquery'
        ],
        bootstrap: 'vendor/bootstrap'
    },
    shim: {
        bootstrap: {
            deps: ['jquery'],
            exports: 'jquery'
        }
    }
});

When I am in the directory and run "grunt" in the Terminal, when it gets to the requirejs:dist step, I receive the following error:

[Error: Error: paths fallback not supported in optimizer. Please provide a build config path override for jquery
    at /Users/myaccount/Sites/test/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:24325:23
]

Is there an error in the way I've formatted the path fallback?

Set a configuration value on runtime

In my require.config.js I have this logic:

var gaId = 'UA-46775653-';

if (window.PRODUCTION)
    gaId += '3';

else if (window.STAGING)
    gaId += '2';

else
    gaId += '1';

requirejs.config({
    baseUrl: '/scripts',
    config: {
        'GA': {
            'id': gaId,
            'fields': {
                'forceSSL': true
            }
        }
    },
    ...
}

This because I want to set the ID for Google Analytics on runtime, depending on the environment I am in.

This works fine unless I am minifying the whole JS shebang via grunt. grunt-contrib-requirejs complains:

[Error: Error: The config in mainConfigFile /home/michael.heuberger/projects/binarykitchen/code/signdna/client/scripts/config/require.config.js cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer.
Source error from parsing: /home/michael.heuberger/projects/binarykitchen/code/signdna/client/scripts/config/require.config.js: ReferenceError: gaId is not defined
    at Function.build.createConfig (/home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:25024:23)
]

Of course, the plugin wants a static JSON. Understandable.

Is there a way I can somehow set the gaId variable via grunt to solve this error?

requirejs test throwing error in uglify

I get this error when i run uglify in grunt. It's coming from one of the files in the test folder and breaks my build.

 Error: Cannot uglify2 file:
>> /Users/dan/Documents/od/Fuel-OD/public/build/js/bower_components/requirejs/te
>> sts/browsertests/onerror/parseError.js. Skipping it. Error is:
>> Unexpected token: punc ({) (line: 2, col: 17, pos: 18)
>> 
>> Error
>>     at new JS_Parse_Error
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16086:22)
>>     at js_error
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16092:15)
>>     at croak
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16463:13)
>>     at token_error
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16466:13)
>>     at unexpected
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16470:13)
>>     at semicolon
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16485:76)
>>     at simple_statement
>> (/Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mo
>> dules/requirejs/bin/r.js:16638:48)
>>     at
>> /Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mod
>> ules/requirejs/bin/r.js:16524:78
>>     at
>> /Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mod
>> ules/requirejs/bin/r.js:16496:28
>>     at
>> /Users/dan/Documents/od/Fuel-OD/node_modules/grunt-contrib-requirejs/node_mod
>> ules/requirejs/bin/r.js:17198:42
Warning: RequireJS failed. Use --force to continue.

Aborted due to warnings.

Node's FileSystem won't run during build

Not sure why, but any calls to FileSystem never successfully run during a build.

var fs = require.nodeRequire('fs');
var path = 'absolute/path/to/file.css';
console.log(path);
fs.exists(path, function(exists) {
console.log('exists? ' + exists);
})

When you grunt -d, it logs the path, but you don't see the log inside the exists callback. Same goes for any other fs call, sync or not.

This works fine when calling node r.js directly.

paths configuration madness

Hello, I am having a real nightmare for this plugin to work.
The problem is in the paths configuration, for some reason it mixes them.

Directory structure:

www/
  js/
    (same as lower)
grunt/
  Gruntfile.js
  build/
    js/
      app.js
      bootconfig.min.js
      collection/
      config.js
      events.js
      libs/
      main.js
      model/
      nls/
      router.js
      services/
      utils/
      views/
      vm.js

The config.js file:

require.config({
    deps: ['main'], //load main.js

    locale: 'en-us',

    //TODO remove
    urlArgs: "bust="+ (new Date()).getTime(), //cache killer

    // Paths that contain the various different javascript files.
    paths: {
        libs: 'libs', //path to libs folder relative to current folder

        plugins: 'plugins',
        services: 'services',
        templates: '../templates',
        translations: 'translations',

        jquery: 'libs/jquery-1.9.1.min',
        underscore: 'libs/underscore-1.4.4.min',
        bootstrap: 'libs/bootstrap-2.3.0.min',
        backbone: 'libs/backbone-0.9.10.min',
        //iscroll: 'libs/iscroll-lite',
        iscroll: 'libs/iscroll',

        syncHandler: 'services/syncHandler',

        text: 'libs/require.text-2.0.5.min',
        domready: 'libs/require.domReady-2.0.1.min',
        i18n: 'libs/require.i18n-2.0.2.min',

        forcetk : 'libs/forcetk'
    },

    shim: {
        bootstrap: {
            deps: ['jquery']
        },
        backbone:{
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        underscore:{
            exports:'_'
        },
        jquery:{
            exports: 'jQuery'
        },
        forcetk:{
            deps:['jquery'],
            exports:'forcetk'
        },
        iscroll: {
            exports: 'iScroll'
        }
    }
});

And now the error messages and the corresponding tested conf:

mainConfigFile: "./build/js/config.js",
name: './build/js/main.js',
out: './build/js_opti/app.concat.min.js',

Error: ENOENT, no such file or directory
'/var/www/xxx/trunk/grunt/build/js/build/js/main.js'
double 'build/js' ??

mainConfigFile: "./build/js/config.js",
name: 'main.js',
out: './build/js_opti/app.concat.min.js',

Error: ERROR: module path does not exist: main.js for module named: main.js.
Path is relative to: /var/www/xxx/trunk/grunt
'build/js' gone ??

mainConfigFile: "./build/js/config.js",
name: 'build/js/main.js',
out: './build/js_opti/app.concat.min.js',

Error: ENOENT, no such file or directory
'/var/www/xxx/trunk/grunt/build/js/build/js/main.js'
and back again

I also tried multiple combinations with appDir, baseUrl, .... without luck.

I am sure to be missing something basic, any idea please ?

Error: Error: nope at check

This is a error from r.js that simply says "nope".

I'm getting this when trying grunt requirejs.

Its firing from line 2789 in node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js

My task is configured like this:

    requirejs: {
      compile: {
        options: {
          baseUrl: ".",
          name: 'lib/MyThing,
          paths: {
            jquery: 'bower_components/jquery/jquery',
            underscore: 'bower_components/underscore/underscore',
            backbone: 'bower_components/backbone/backbone',
            select2: 'bower_components/select2/select2',
            text: 'bower_components/requirejs-text/text'
          },
          shim: {
            'underscore': {
              exports: '_'
            },
            'backbone': {
              deps: ['jquery', 'underscore'],
              exports: 'Backbone'
            },
            'select2': {
              deps: ['jquery'],
              exports: 'jQuery.fn.select2'
            }
          },
          out: "MyThing.built.js"
        }
      }
    },

require-confile file size

After running the grunt task all the js files got minified but the size of require-config file increased from 3 kb to 166 kb. I am really not sure what is the reason. Let me know if someone need more details on this.

Ignores "optimize" property

If I set optimize: "none", this works in my normal r.js config, but this tool seems to ignore it and uglify my javascript anyway.

Error: Mismatched anonymous define() module: undefined

Hi,
i am having a issue its not when i compile it comes when i run my app.
when i run app browser console show error
"Error: Mismatched anonymous define() module: undefined" and few other errors that comes because of require js failed to start as expected.

I dived in an noticed if goes to "node_modules/grunt-contrib-requirejs" and edit package.json file and changes dependencies: {requirejs: '~2.10'} version to '2.1.6' and compile my files with grunt then all works fine.

it seems the requirejs version 2.1.8 (this lates one and is installed by default) have some breaking changes.

any help to make it work smooth instead of manulay hacking stuff.

Thank You

Only after compile: "underscore" has not been loaded yet for context.

Here is my requirejs task:

  requirejs: {
    compile: {
        options: {
          mainConfigFile: 'app/main.js',
          name: 'main',
          include: compileList, // A list of our widgets pulled in from other repos
                                                // through bower
          paths: {
            'jquery': 'bower_components/jquery/jquery',
            'jquery-ui': 'bower_components/jquery-ui-amd/jquery-ui-1.10.0/ui/minified/jquery-ui.min',
            'bootstrap': 'bower_components/bootstrap/docs/assets/js/bootstrap.min',
            'underscore': 'bower_components/underscore/underscore'
          },
          shim: {
            'jquery-ui': {deps: ['jquery']},
            'bootstrap': {deps: ['jquery', 'jquery-ui']},
            'backbone':  {
              deps: ['jquery', 'underscore'],
              exports: 'Backbone'
            }
          },
          exclude: ['jquery', 'jquery-ui', 'bootstrap'],
          insertRequire: ['main'],
          out: 'dist/<%= pkg.name %>.js'
       }
      }
    }

When I try to load my page I keep getting the error
Module name "underscore" has not been loaded yet for context: _. Use require([]) but this doesn't happen when I run the un-compiled version of our app.

I had to exclude jquery, jquery-ui and bootstrap because those were throwing other errors (it kept telling me jQuery is not defined).

I'm sure I'm just not setting some option correctly. I've been fiddling with the shim, insertRequire and keepAmdefine but I can't get the underscore error to resolve.

[Error: TypeError: undefined is not a function

Hello,

Having problem while using this plugin. Your help is much appreciated.

When running grunt I have the following error:

 Running "requirejs:compile" (requirejs) task
 >> Tracing dependencies for: main
 >> TypeError: undefined is not a function
 >> In module tree:
 >>     main
 >>       view/layout/app
 >>         router
 >>           view/homepage
 >>             view/carousel
 >>               hbs
 [Error: TypeError: undefined is not a function
 In module tree:
     main
       view/layout/app
         router
           view/homepage
             view/carousel
               hbs

at recursiveNodeSearch (eval at <anonymous> (/Applications/MAMP/htdocs/app/http_dev/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:22988:38), <anonymous>:140:15)
 ]

I think it has problem finding "hbs". Although it works fine in the browser.

require.config.js is as follow.

requirejs.config({
    baseUrl: "js",

    // HandleBar Config
    hbs: {
        disableI18n: true,
        disableHelpers: true,
        templateExtension: "hbs"
    },
    map: {
        'hbs': {
            'hbs/underscore': 'underscore'
        }
    },
    paths: {
        underscore: "libs/underscore",
        backbone: "libs/backbone/backbone",
        jquery: "libs/jquery-1.8.1.min",
        modernizr: "libs/modernizr.custom-2.6.2.030413",
        royalSlider: "libs/jquery.royalslider-9.3.7.custom.min",
        Handlebars: "libs/Handlebars",
        hbs: "libs/hbs"
    },
    shim: {
        "backbone": {
            //These script dependencies should be loaded before loading
            //backbone.js
            deps: ["underscore", "jquery"],
            //Once loaded, use the global "Backbone" as the
            //module value.
            exports: "Backbone"
        },
        "underscore": {
            exports: "_"
        },
        "jquery": {
            exports: "$"
        },
        "Handlebars": {
            exports: "Handlebars"
        },
        "royalSlider": {
            deps: ["jquery"]
        }
    }
});

// Load the main app module to start the app
requirejs(["main"]);

Extract of Gruntfile.js is as follow:

grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        requirejs: {
            compile: {
                options: {
                    name: "main",
                    baseUrl: "js",
                    mainConfigFile: "js/config.js",
                    out: "js/optimized.js",
                    useSourceUrl: true,
                    keepBuildDir: true
                }
            }
        }
    });

Code can be downloaded here:
https://www.dropbox.com/s/yyc6baufj7nqm67/http_dev.zip

EADDRINUSE error when used with grunt-contrib-watch

node: v0.8.14
npm: v1.1.65
grunt-contrib-watch: v0.1.4
grunt-contrib-requirejs: v0.3.4

I get the following error when listening for a change to JS files using grunt-contrib-watch:

>> File "js/modules/detect.js" changed.
TC Listener running on http://0.0.0.0:1980
Running "requirejs:compile" (requirejs) task
>> events.js:71
>> throw arguments[1]; // Unhandled 'error' event
>> ^
>> Error: listen EADDRINUSE
>>     at errnoException (net.js:769:11)
>>     at Server._listen2 (net.js:909:14)
>>     at listen (net.js:936:10)
>>     at Server.listen (net.js:985:5)
>>     at Object.<anonymous> (/Users/ahume/Sites/pasteup/build/tclisten.js:23:4)
>>     at Module._compile (module.js:449:26)
>>     at Object.Module._extensions..js (module.js:467:10)
>>     at Module.load (module.js:356:32)
>>     at Function.Module._load (module.js:312:12)
>>     at Module.require (module.js:362:17)

I would like to have two "out" files.

How could I do this? out cannot support arrays

I cant have two "requirejs" tasks

requirejs: {
  compile: {
      options: {
          baseUrl: "assets/javascripts",
          name: 'main',
          mainConfigFile: "assets/javascripts/main.js",
          out: "../shopify/reggi-4204209/assets/main.js"
      }
  }
},
requirejs_two: {
  compile: {
      options: {
          baseUrl: "assets/javascripts",
          name: 'main',
          mainConfigFile: "assets/javascripts/main.js",
          out: "../mylife/assets/main.js"
      }
  }
},

Or use subtask

requirejs:{
    "shopify:{},
    "wordpress:{}
}

Support for Map?

I was wondering if this was a problem with grunt-contrib-require or just a problem with my code. I'm trying to replicate this answer on stackoverflow, it's also in the requirejs docs.

Here's my code:

require.config({
    paths: {
        "jquery": "../../bower_components/jquery/jquery",
    },
    map: {
      "*": {
        "jquery": "noconflict"
      },
      "noconflict": {
        "jquery": "jquery"
      }
    }
});

define(["jquery"], function($) {
  return $.noConflict(true);
});

define("main", function(){
    var $ = require("jquery");
    console.log($().jquery);
});

require(["main"]);

Here's the error:

Running "requirejs:main" (requirejs) task
>> Tracing dependencies for: main
>> Error: ENOENT, no such file or directory
>> '/Users/user/.../noconflict.js'
>> In module tree:
>>     main

upgrade requirejs to 2.1.10

requirejs 2.1.10 has a bunch of fixes and supports mainConfigFile as an array. Any change you can update the dependency for this project also?

onOptimize

Would you be interested in a pull request that offered the ability for an onOptimize request that passes the build results? This would allow additional tooling after a r.js build that doesn't really fit in a separate task (or require the build.txt file).

M

Error: Unexpected token }

It raise cpationed error when parse below code:

function isUseStrict(stmt) {
return options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" &&
    stmt.expression.type === "Literal" && stmt.expression.value === "use strict";

}

Seems there is a bug on parsing "use strict"

Problem with getting grunt-requirejs compile to work

Since most issues with require.js build has to do with file structure and relative path reference, I created a repo here: https://github.com/ttback/requirejs-example for easier troubleshoot.

The error is when i run grunt, I will get no such file or directory requirejs-example/src/js/bundle/js/bundle/utils.js

This is due to the wrong baseUrl. I want it to be src/ but I can't set it since it goes to find the dependencies for src/js/bundle/main.js based on my Gruntfile. So the base is at src/js/bundle. The current main.js works with the index.html, if I change the relative path to utils.js from .js/bundle/utils.js to ./utils.js inside main.js, the app wil break.

Is there any way I can make the grunt-requirejs work with what I have?

If you specify a 'done' method option, subsequent configured tasks will not execute

Looks like using the 'done' option blocks any tasks which would follow it. Here's the scene:

grunt.task.run [ 'copy:js', 'requirejs', 'clean:unoptimizedFiles' ] # clean:unoptimizedFiles Won't run right after requirejs for some reason.

It does not run that clean step, and there is no output referring to that step, even in verbose mode. If I run the step separately, it is successful.

When I comment out the done option, however, tasks following requirejs work again.

requirejs:
  oneForAll:
    options:
      ...
      optimize: "none"
#          done: (done, output) -> # commenting this out fixes it
#            duplicates = require('rjs-build-analysis').duplicates(output)
#            if duplicates.length > 0
#              grunt.log.subhead 'Duplicates found in requirejs build:'
#              grunt.log.warn duplicates
#              done new Error 'r.js built duplicate modules'
#            done()

Issues with nested requirejs configs

In this issue thomaswelton/requirejs-google-analytics#7 I have documented that there are nested requirejs configs and this is messing up with grunt-contrib-requirejs.

In https://github.com/thomaswelton/requirejs-google-analytics/blob/master/dist/GoogleAnalytics.js#L14 you see a path and shim definition. If I copy that into my grunt file then it works. But IMO this is code duplication and not good.

Please read the above issue for details. Any advice / feedback is very welcome.

Thanks!

Usage Example Fail

This usage example here does not work

requirejs: {
  compile: {
    options: {
      baseUrl: "path/to/base",
      mainConfigFile: "path/to/config.js",
      out: "path/to/optimized.js"
    }
  }
}

You get Error: Missing either a "name", "include" or "modules" option every time.

Almond support

The support for almond is not very well documented. I have seen the use of the "name" attribute to reference the almond lib. Since almond is mentioned in the example.build.js file, I assume that it is already possible to configure almond as replacement for require. But it's still quite unclear.

Next to that I am also curious how the "include" and "insertRequire" options relate to the "name" option. Can anyone explain?

Build script does not run main script

I have another gotcha: With the following configuration in my Gruntfile.coffee I am unable to run the main script in the browser:

    requirejs:
      compile:
        options:
          baseUrl: "client/scripts/compiled"
          name: 'main'
          mainConfigFile: "client/scripts/compiled/config/require.config.js"
          out: "server/public/j/main.js"
          useStrict: true
          optimize: 'none'
          preserveLicenseComments: false

server/public/j/main.js has all the source code but does not run anything. At the bottom I see this line which makes no sense:

define("main", function(){});

Any clues?

Support for closure compiler?

if I try to use the closure compiler for minifying, I get this error message:

"Error: optimizer with name of "closure" not found for this environment"

i18n plugin no longer works

This bug was introduced in the most recent commit, 830ae96. I'm seeing results where running grunt requirejs picks up my root nls files but not the translation files themselves. (So nls/colors.js is included in the generated file, but not nls/fr-fr/colors.js.) If I downgrade nothing but grunt-contrib-requirejs to 48a1421, this works correctly.

I'm not sure what source would be helpful to see here. The code I'm working with is actually just for proofing i18n for my project, and is taken directly from the i18n example from the requirejs docs. http://requirejs.org/docs/api.html#i18n

The requirejs settings from my Gruntfile: https://gist.github.com/4649422

The config hash from my app's requirejs config file, manually setting a locale: https://gist.github.com/4649451

And for what it's worth, the one source file where I reference the translations: https://gist.github.com/4649433

Let me know if there's any other source that might be helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.