我们已经按照https://github.com/javascript-obfuscator/webpack-obfuscator实现了模糊器,我们的项目根目录下只有三个子文件夹:node_modules,src,dist.我们希望这些插件都可以使用exclude in插件进行非模糊处理,因此包中的后续代码根本不会被模糊处理(当然,这只是确保exclude可以正常工作的中间步骤。最后,我们只想从模糊处理中排除node_modules)。
javascript模糊器(4.0.0)和webpack-obfuscator(3.5.1)版本都是最新的,因此应该是兼容的?!
包.json
{
"name": "metrolyzer_npm",
"version": "1.0.0",
"description": "includes information about all modules required for the Metrolyzer",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch",
"build": "webpack"
},
"repository": {
"type": "git",
"url": "https://git.jetbrains.space/else42/metro/metrolyzer.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"autoprefixer": "^10.4.13",
"bootstrap": "5.0.2",
"css-loader": "^6.7.2",
"d3": "^7.7.0",
"dat.gui": "0.7.7",
"javascript-obfuscator": "^4.0.0",
"jquery": "3.6.0",
"postcss-loader": "^7.0.2",
"sass": "^1.56.1",
"sass-loader": "^13.2.0",
"style-loader": "^3.3.1",
"three": "0.123.0",
"three-orbit-controls": "^82.1.0",
"three.meshline": "^1.4.0",
"troika-three-text": "0.45.1",
"xlsx": "0.10.8"
},
"keywords": [],
"devDependencies": {
"webpack": "^5.75.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1",
"webpack-obfuscator": "^3.5.1"
}
}
网络包配置js
const path = require('path');
var WebpackObfuscator = require('webpack-obfuscator');
module.exports = {
mode: 'production',
entry: {
index: './src/index.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '',
sourceMapFilename: "[name].js.map" // Allows us to get more detailed information about the source of an error
},
devtool: "source-map", // Allows us to get more detailed information about the source of an error
optimization: {
minimize: false, // Minimization should enabled for production
},
plugins: [
new WebpackObfuscator({rotateStringArray: true}, ['*node_modules*','*src*','*dist*'])
],
module: {
rules: [
{
test: /\.(sass|css)$/,
use: [ // The use of a loader is required because we are using .css from bootstrap
'style-loader',
'css-loader',
]
},
{
test: /\.js$/,
exclude: [
path.resolve(__dirname, 'node_modules')
],
enforce: 'post',
use: {
loader: WebpackObfuscator.loader,
options: {
rotateStringArray: true
}
}
}
]
}
};
1条答案
按热度按时间qq24tv8q1#
更新:我们能够重现并解决这个问题。为了使文件夹/文件的排除起作用,必须更改两件事。
1.拆卸管路:从变量
plugins
中提取new WebpackObfuscator({rotateStringArray: true}, ['*node_modules*','*src*','*dist*'])
。我们怀疑这是多余的。1.指定应排除的文件夹/文件时,请使用
path.join()
而不是path.resolve()
。path.resolve()
将导致C:\node_modules
而不是C:\Users\ ... \ ... \ ... \node_modules\
实施这些更改后,我们的问题得到了解决。以下是生成的webpack.config.js。可以忽略除1.和2.中所述之外的配置更改。