3 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個贊
只是建立在felismosh的回答對你將要CLI將不包括--mangle
或--compress
命令,如果你想要做的就是刪除空格和換行。
所以它會更像: terser original-file.js -o minified-file.js
.
除非在 CLI 命令中明確打開,否則 Mangle 和 compress 將被禁用。

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個贊
這將禁用壓縮并使用輸出選項(xiàng)來刪除注釋。該extractComments屬性可防止插件將注釋提取到文本文件中。
module.exports = {
/* ... */
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: false,
output: {
comments: false,
},
},
extractComments: false,
}),
],
},
};

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個贊
直接使用 terser 無需 webpack。運(yùn)行npm i terser安裝它,然后您將有2個選擇:
使用它的 cli, terser --compress --mangle -- input.js.
使用它的 api 來自節(jié)點(diǎn),
const Terser = require('terser');
const code = {
'file1.js': 'function add(first, second) { return first + second; }',
'file2.js': 'console.log(add(1 + 2, 3 + 4));',
};
const options = {
ecma: undefined,
warnings: false,
parse: {},
compress: {},
mangle: false,
module: false,
toplevel: false,
keep_classnames: true,
keep_fnames: true,
};
const result = Terser.minify(code, options);
console.log(result.code);
添加回答
舉報(bào)