1

I've this dir structure:

webapp     
  ├──static
  │   ├── app
  │        ├── config.js
  │        ├── frontpage.js
  │        ├── profile.js
  │        └── utils.js
Gruntfile.js

And I'm trying to use grunt-contrib-requirejs to optimize my dependencies for profile and frontpage. Now my config.js looks like:

    require.config({
        {
          baseUrl:"/static/app",
          shim: {
           bootstrap : { "deps" :['jquery'] } ,
           velocity : { "deps" : ['jquery']}
          },
          paths: {
            jquery: "../bower_components/jquery/dist/jquery.min",
            bootstrap : "//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min",
            requirejs: "../bower_components/requirejs/require",
            handlebars: "../bower_components/handlebars/handlebars.min",
            velocity: "../bower_components/velocity/velocity.min"

          },
          packages: []
        });

I tried the following config for grunt-require-config

requirejs: {
          compile: {
            options: {
              appDir: "static/app",
              modules : [
                {
                    name: "profile"                 
                }
              ],
              mainConfigFile: "./static/app/config.js",
              optimize: "none",
              dir: "./static/build/"
            }
          }
        }

but I get this error:

Running "requirejs:compile" (requirejs) task
{ [Error: Error: ERROR: module path does not exist: /static/app/profile.js for module named: profile. Path is relative to: /webapp
 [..]

which is strange, because that path is correct!

I can't find many examples of this around, can anyone help?

UPDATE:

All I needed was to adjust the baseUrl in the Gruntfile.js and I removed appDir. The baseUrl in the requirejs options is now the same as in the config.

requirejs: {
          compile: {
            options: {          
              baseUrl: "static/app",
             /* modules : [
                {
                    name: "profile"

                },
                {
                    name: "frontpage"

                }
              ],*/
              mainConfigFile: "./static/app/config.js",
              optimize: "none",
              dir: "./static/build/"
            }
          }
        }
gotch4
  • 13,093
  • 29
  • 107
  • 170

1 Answers1

0

Because your config.js and profile.js has the same path your baseUrl in config is wrong.

I tested this configuration in my machine and is working.

Gruntfile.js

module.exports = function(grunt) {

grunt.initConfig({
    requirejs: {
        compile: {
            options: {
              appDir: "webapp/static/app",
              modules : [
                {
                    name: "profile"
                }
              ],
              mainConfigFile: "webapp/static/app/config.js",
              optimize: "none",
              dir: "./dist/"
            }
        }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-requirejs');


  grunt.registerTask('default', ['requirejs']);

};

config.js

require.config(
{
  baseUrl:".",
  packages: [],
}
);
Fetz
  • 1,196
  • 8
  • 11
  • I need the baseUrl in the config to be the way it is in my code. But I managed to find a way to make it work, see above – gotch4 May 06 '15 at 12:42