我正在使用 webpack 4 将一系列带有导入/导出的 TypeScript 文件捆绑到单个 bundle.js 中。然后我尝试使用 Terser 来混淆最终输出。我得到了有效的输出,但是,在我的代码中作为顶级函数开始的东西是由 webpack 以 Terser 拒绝破坏函数名称的方式输出的。
任何想法如何让 Terser 重命名这些函数或如何让 webpack 输出而不使用下面的webpack_require行,这似乎通过将我的函数变成对象上的方法来通过 Terser。
function setCommands() {
//My original function here. Looking to have "setCommands" get renamed for obfuscation.
}
//Terser appears not to mangle the above name due to the below code...
//How can I obfuscate with this via Terser or get webpack to not output this?
//Other stuff created by webpack for bundle.js output
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setCommands", function() { return _panelUI__WEBPACK_IMPORTED_MODULE_16__["setCommands"]; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setCommands", function() { return setCommands; });
参考:webpack.config.js 文件...
const path = require('path');
module.exports = {
mode: 'none',
entry: './src/js/startHere.ts',
devtool: 'source-map',
output: {
filename: '../dist/bundled.js',
path: path.resolve(__dirname, './'),
},
watch: true,
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
enforce: 'pre',
exclude: /node_modules/,
use: 'tslint-loader',
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: 'ts-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
performance: {
//suppress yellow errors about file size.
hints: 'warning',
maxEntrypointSize: 3000000,
maxAssetSize: 3000000,
},
};