Reputation: 20091
I am minifying multiple files in a folder using uglifyjs-folder
in npm
package.json
like :
"uglifyjs": "uglifyjs-folder js -eyo build/js"
It is working as intended & minify all files in folder.
I want to remove any console.log & alert while minify but not able to find any option with uglifyjs-folder
https://www.npmjs.com/package/uglifyjs-folder
Please help.
Upvotes: 1
Views: 717
Reputation: 5220
uglify-folder
(in 2021, now?) supports passing in terser configs like so:
$ uglify-folder --config-file uglifyjs.config.json ...other options...
and with uglifyjs.config.json
:
{
"compress": {
"drop_console": true
}
}
And all options available here from the API reference.
Upvotes: 0
Reputation: 24992
Unfortunately, uglifyjs-folder does not provide an option to silence the logs.
You could consider writing a nodejs utility script which utilizes shelljs to:
uglifyjs-folder
command via the shelljs
exec()
method.exec()
methods silent
option.The following steps further explain how this can be achieved:
Install
Firstly, cd
to your project directory and install/add shelljs by running:
npm i -D shelljs
node script
Create a nodejs utility script as follows. Lets name the file: run-uglifyjs-silently.js
.
var path = require('path');
var shell = require('shelljs');
var uglifyjsPath = path.normalize('./node_modules/.bin/uglifyjs-folder');
shell.exec(uglifyjsPath + ' js -eyo build/js', { silent: true });
Note: We execute uglifyjs-folder
directly from the local ./node_modules/.bin/
directory and utilize path.normalize()
for cross-platform purposes.
package.json
Configure the uglifyjs
script inside package.json
as follows:
{
...
"scripts": {
"uglifyjs": "node run-uglifyjs-silently"
...
},
...
}
Running
Run the script as per normal via the command line. For example:
npm run uglifyjs
Or, for less logging to the console, add the npm run
--silent or shorthand equivalent -s option/flag. For example:
npm run uglifyjs -s
The example gist above assumes that run-uglifyjs-silently.js
is saved at the top-level of your project directory, (i.e. Where package.json
resides).
Tip: You could always store run-uglifyjs-silently.js
in a hidden directory named .scripts
at the top level of your project directory. In which case you'll need to redefine your script in package.json
as follows:
{
...
"scripts": {
"uglifyjs": "node .scripts/run-uglifyjs-silently"
...
},
...
}
Upvotes: 1