I am trying to get up and running with the grunt-contrib-requirejs task.
Being new to RequireJS in general and having never used the optimizer/r.js, I am really confused how to get this to work.
As a start, I have set up a simple directory structure like this:
root
├── js
│ ├── helper
│ │ ├── a.js
│ │ ├── b.js
│ │ └── d-dep.js
│ └── main.js
├── node_modules
│ └── [dependencies from package.json]
├── Gruntfile.js
└── package.json
I've tested it in the browser and all dependencies are loaded correctly there.
My Gruntfile:
module.exports = function(grunt) {
grunt.config.init({
requirejs: {
options: {
baseUrl: 'js/',
mainConfigFile: 'js/main.js',
dir: 'target/',
keepBuildDir: true
}
}
});
require('load-grunt-tasks')(grunt);
}
main.js:
require(["helper/a", "helper/b"], function(util) {
console.log('main.js loaded');
});
a.js
console.log('a.js loaded');
b.js
define(['js/helper/b-dep.js'], function(bdep) {
console.log('b.js loaded');
});
b-dep.js
console.log('b.js dependency loaded');
When running grunt requirejs
, I get a Done, without errors.
message, but can't see any optimized file – I am guessing the error is in the Gruntfile, probably with the path.
Do you see anything that strikes you? Why is nothing optimized, although it says Done, without errors.
?