Reputation: 3210
I am using requirejs to build frontend on play 2.2 framework. play provides great development/stage code difference for this case. In devel mode I am working with browser based requirejs and in stage I am using precompiled with r.js version of the project. But one feature fails - is it possible to distinguish on javascript side is it development mode or not and remove part of code during compilation or something like:
#ifdef DEVELOPMENT
code in Development only
#endif
Upvotes: 0
Views: 122
Reputation: 3210
UglifyJS2 from sbt-rjs 1.0.7 already has some other usefull option:
uglify: {
drop_console: true
}
uglify2: {
compress: { drop_console: true }
}
it removes all console.log messages from minified script.
Upvotes: 0
Reputation: 151511
By default r.js
uses UglifyJS to optimize your modules. In r.js
' configuration you can use the uglify
option to send configuration options to UglifyJS. For instance,
uglify: {
defines: {
DEV: ['name', 'false']
}
},
This would tell uglifyjs
replace every instance of the symbol DEV
with the name false
. Then, parts like this:
if (DEV) {
// ....
}
would be automatically removed by uglifyjs
as being unreachable.
See uglifyjs
' documentation for the details of how that works.
You might also want to look at UglifyJS2, because it perhaps does more than UglifyJS. You can tell r.js
to use it by setting the optimize
option to uglify2
, and use the uglify2
option to control what it does.
Upvotes: 1