I have been battling with this for a while (even used some Ant-based workarounds), even posted a question that went unanswered: older similar/related question.
Require.js allows to build several modules using the same profile/config file. For example:
({
appDir: 'some/path',
baseUrl: 'some/base/path',
dir: 'some/other/path',
optimize: 'none',
paths: {
...
},
modules: [
{
name: 'someModule',
},
{
name: 'someOtherModule'
}]
})
Which works fairly well. Additionally, Require.js provides an option to override any option for the build for a specific module: Require/js example build configuration, like this :
({
appDir: 'some/path',
baseUrl: 'some/base/path',
dir: 'some/other/path',
optimize: 'none',
paths: {
...
},
modules: [
{
name: 'someModule',
},
{
name: 'someModule',
override : {
optimize: 'uglify'
}
}]
})
or so I understood it. The purpose is to use the same build configuration file on the same application, but have it both non-minified and minified. This doesn’t work.
EDIT
The error I am getting is (cleaned up, since it is part of a larger Ant build):
Error: ENOENT, no such file or directory 'some/other/path/someModule.js-temp'
Any help, suggestions (on both questions) are greatly appreciated.
The listing of modules: config does not allow duplicates for the name value. I suspect that is the source of the problem. It is an array just to allow proper sequencing of build layers that may be excluded in other build layers — using an object hash would not work since key iteration on an object does not guarantee order.
If you want to do a build that has the layer in non-minified and minified format, I suggest driving the build via a node script, then manually requiring uglify and doing a copy of the built file and minification of that copy after the build.
Here is an example of a node script that drives the build:
https://github.com/jrburke/r.js/blob/master/build/tests/tools/override/override.js
That one is replacing the version of uglify used, but you could use it and do the file copy/manual minification in the callback function passed to requirejs.optimize().