I dont think the accepted answer is of use. I know its an old question but I ran into the same problems so here is my solution, not for the thread starter but for people in the same situation.
The main problem you probably have is that your require-files are setup in the wrong way. The reason why the grunt job doesnt include all files is most likely because the files aren't properly required or defined. It has nothing todo with the grunt job.
It's not enough to have a config file (app.js in your case), you also need to require the files. For example you can do that in a main.js file:
require(["global","highcharts-chartdata"], function () {});
Please have a look at my setup that works. This is the folder structure:
Project
|
├───dist
| ├───css
| | bundle.css
| ├───fonts
| ├───images
| └───js
| bundle.js
| index.html
|
└───src
├───js
│ └───vendor
│ ├───bootstrap
│ ├───highcharts
│ ├───jquery
│ └───require
| require.js
| charts.js
| global.js
| main.js
| require.config.js
└───less
├───bootstrap
│ └───mixins
├───bootstrap_overrides
└───font-awesome
gruntfile.js
This is my gruntfile:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['src/js/*.js'],
options: {
globals: {
$: false,
console: true,
module: true,
document: true
}
}
},
less: {
compile: {
options: {
paths: ['src/less'],
plugins: [
new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]}),
new (require('less-plugin-clean-css'))
]
},
files: {
'dist/css/bundle.css': 'src/less/style.less'
}
}
},
requirejs: {
compile: {
options: {
baseUrl: "src/js",
mainConfigFile: 'src/js/require.config.js',
paths: {
requireLib: "vendor/require/require"
},
include: "requireLib",
name: "require.config",
out: "dist/js/bundle.js"
}
}
},
watch: {
files: ['src/js/*.js','src/less/**/*.less'],
tasks: ['jshint','less','requirejs']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-requirejs');
// Default task(s).
grunt.registerTask('default', ['jshint','less','requirejs']);
};
This is the require.config-file:
requirejs.config({
baseUrl: 'js',
paths: {
"jquery": "vendor/jquery/jquery",
"jquery-ui": "vendor/jquery/jquery-ui",
"bootstrap-collapse": "vendor/bootstrap/collapse",
"bootstrap-transition": "vendor/bootstrap/transition",
"highcharts": "vendor/highcharts/highcharts-4.1.4.min",
"highcharts-chartdata": "charts"
},
shim: {
"bootstrap": ["jquery"],
"jquery-ui": ["jquery"],
"bootstrap-collapse": ["jquery"],
"bootstrap-transition": ["jquery"],
"highcharts" : ["jquery"],
"highcharts-chartdata" : ["highcharts"]
}
});
// Load the main app module to start the app
requirejs(["main"]);
Please observe that the line above requirejs(["main"]);
is actually "loading" the code in my main.js-file (below) which in its turn is loading other files:
require(["global","highcharts-chartdata"], function () {});
Without those, grunt-contrib-requirejs wont know what to include.
In our case we want to output a single js-file (optimized.js) to be included in your start page (index.html). For this to work I want point out that we need to add the require.js-script as well, without it the console would just say require is not defined
.
To do that you just add the following rows in your gruntfile:
paths: {
requireLib: "vendor/require/require"
},
include: "requireLib",
You can read about it here: http://requirejs.org/docs/optimization.html#onejs