提交 b967585a 作者: 毛细亚

测试自己的构建配置

上级 45092d53
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
]
}
module.exports = { module.exports = {
// 自己的混淆配置
my: {
stringArray: true, // 压缩成一行
// 僵尸代码
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
// debugProtection: true,// 此选项几乎不可能使用开发者工具的控制台选项卡
// debugProtectionInterval: true,// 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。
log: true,// 是否允许将信息记录到控制台。
// disableConsoleOutput: false,// 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。
// identifierNamesGenerator: 'hexadecimal', //标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符)
identifiersPrefix:'_zwan_',//全局标识符添加特定前缀,在混淆同一页面上加载的多个文件时使用此选项。此选项有助于避免这些文件的全局标识符之间发生冲突。为每个文件使用不同的前缀
inputFileName: '',
renameGlobals: true,// 是否启用全局变量和函数名称的混淆
rotateStringArray: true,// 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意
// 编码的所有字符串文字stringArray使用base64或rc4并插入即用其解码回在运行时的特殊代码。true(boolean):stringArray使用编码值base64;false(boolean):不编码stringArray值;'base64'(string):stringArray使用编码值base64;'rc4'(string):stringArray使用编码值rc4。大约慢30-50%base64,但更难获得初始值。建议禁用unicodeEscapeSequence带rc4编码的选项以防止非常大的混淆代码。
stringArrayEncoding: ['none'],
stringArrayThreshold:0.5,
// 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。
target: 'browser',
// 是否启用混淆对象键
transformObjectKeys: true,
unicodeEscapeSequence: false
},
// 轻度的混淆配置
simple: { simple: {
compact: true, compact: true,
controlFlowFlattening: false, controlFlowFlattening: false,
...@@ -12,10 +37,11 @@ module.exports = { ...@@ -12,10 +37,11 @@ module.exports = {
rotateStringArray: true, rotateStringArray: true,
selfDefending: true, selfDefending: true,
stringArray: true, stringArray: true,
stringArrayEncoding: false, stringArrayEncoding: ['rc4'],
stringArrayThreshold: 0.75, stringArrayThreshold: 1,
unicodeEscapeSequence: false, unicodeEscapeSequence: false,
}, },
// 中度的混淆配置
ordinary: { ordinary: {
compact: true, compact: true,
controlFlowFlattening: true, controlFlowFlattening: true,
...@@ -36,6 +62,7 @@ module.exports = { ...@@ -36,6 +62,7 @@ module.exports = {
transformObjectKeys: true, transformObjectKeys: true,
unicodeEscapeSequence: false, unicodeEscapeSequence: false,
}, },
// 高度的混淆配置
highly: { highly: {
compact: true, compact: true,
controlFlowFlattening: true, controlFlowFlattening: true,
...@@ -55,5 +82,5 @@ module.exports = { ...@@ -55,5 +82,5 @@ module.exports = {
stringArrayThreshold: 1, stringArrayThreshold: 1,
transformObjectKeys: true, transformObjectKeys: true,
unicodeEscapeSequence: false, unicodeEscapeSequence: false,
}, }
}; }
const fileList = ['game/platform/platform.js','game/library/binary.js'] const fileList = ['subpackage/main.min.js'] // 根目录为src文件夹
// const fileList = ['platform/platform.js']
module.exports = { module.exports = {
fileList, fileList,
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"scripts": { "scripts": {
"s": "rm -rf dist && cross-env ENVIROMENT=simple webpack ", "s": "rm -rf dist && cross-env ENVIROMENT=simple webpack ",
"o": "rm -rf dist && cross-env ENVIROMENT=ordinary webpack ", "o": "rm -rf dist && cross-env ENVIROMENT=ordinary webpack ",
"h": "rm -rf dist && cross-env ENVIROMENT=highly webpack" "h": "rm -rf dist && cross-env ENVIROMENT=highly webpack",
"m": "rm -rf dist && cross-env ENVIROMENT=my webpack "
}, },
"dependencies": { "dependencies": {
"moment": "^2.29.1", "moment": "^2.29.1",
......
...@@ -134,4 +134,4 @@ ...@@ -134,4 +134,4 @@
``` ```
## 具体文档 点击[这里](https://blog.csdn.net/qq_31126175/article/details/86526237) ## 具体文档 点击[这里](https://blog.csdn.net/qq_31126175/article/details/86526237)或者点击[这里](https://www.cnblogs.com/dragonir/p/14445767.html)
\ No newline at end of file \ No newline at end of file
### src为你放需要打包文件的文件夹,需要注意的是,当你在build/fileList 里面 加入你想要打包的文件时,根目录为src, 比如 当你想打包 src/index.js 文件的时候 fileList=['./index.js'] ### 1.src为你放需要打包文件的文件夹,需要注意的是,当你在build/fileList 里面 加入你想要打包的文件时,根目录为src, 比如 当你想打包 src/index.js 文件的时候 fileList=['./index.js']
\ No newline at end of file
### 2.注意事项 webpack mode 最好选择生产环境 选择开发环境 为了调试速度快 会启用 eval-cheap-souce-map eval-source-map 微信小程序里面没有eval函数 所以会报错;
### 3.stringArray: true,// 删除字符串文字并将它们放在一个特殊的数组中 这个属性打开 打包后的文件会报错 建议关闭
### 4.微信小程序的代码包最大为20m 请注意代码大小 identifierNamesGenerator: 'mangled' 用mangled短字符可以降低代码大小,降低stringArrayThreshold的值也可以 范围(0-1)
...@@ -7,7 +7,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin'); ...@@ -7,7 +7,7 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const resolve = (p) => path.resolve(__dirname, "./", p) const resolve = (p) => path.resolve(__dirname, "./", p)
const entryDir = resolve('src') const entryDir = resolve('src')
const outputDir = resolve("dist") const outputDir = resolve("dist")
const Obfuscator = resolve('build/WebpackObfuscator.config.js') const Obfuscator = require('./build/WebpackObfuscator.config.js')
const entryFiles = require('./build/fileList').fileList // 这里是需要打包的文件目录 const entryFiles = require('./build/fileList').fileList // 这里是需要打包的文件目录
const env = process.env.ENVIROMENT.trim(); const env = process.env.ENVIROMENT.trim();
let ObfuscatorType = {}; let ObfuscatorType = {};
...@@ -15,13 +15,11 @@ let ...@@ -15,13 +15,11 @@ let
entry = {}, entry = {},
output = {}; output = {};
// 处理entry和output // 处理entry和output
console.log(entryFiles,'entryFiles')
function configInfi() { function configInfi() {
entryFiles.forEach(dir => { entryFiles.forEach(dir => {
console.log('[ dir ]',dir)
if(dir!=='.DS_Store'){ if(dir!=='.DS_Store'){
entry[dir] = path.resolve(__dirname, `${entryDir}/${dir}`) entry[dir] = path.resolve(__dirname, `${entryDir}/${dir}`)
output.filename = "[name].min.js"; output.filename = "[name]";
output.path = outputDir; output.path = outputDir;
} }
}) })
...@@ -31,31 +29,48 @@ function configInfi() { ...@@ -31,31 +29,48 @@ function configInfi() {
ObfuscatorType = Obfuscator.ordinary ObfuscatorType = Obfuscator.ordinary
}else if(env=='highly'){ }else if(env=='highly'){
ObfuscatorType = Obfuscator.highly ObfuscatorType = Obfuscator.highly
}else if(env=='my'){
ObfuscatorType = Obfuscator.my
}else{ }else{
ObfuscatorType={} ObfuscatorType={}
} }
} }
configInfi() configInfi()
module.exports={ module.exports={
mode:'development', // mode:'development', // 用开发环境 会出现eval字段 小程序不支持eval字段
optimization: { mode:'production',
noEmitOnErrors: true,
minimizer: [
new UglifyjsPlugin({
// 使用缓存
cache: true
}),
]
},
entry, entry,
output, output,
performance:{ // 修改打包代码大小的警告
hints:false, // false 不显示 warning 警告 error 错误
maxEntrypointSize:40000
},
module:{
rules: [
{
test: /\.(js|jsx)$/,
include: "/src/",
use: [{
loader: "babel-loader",
options: {
presets: ['react', 'es2015', 'stage-0'],
}
}],
},
{
test: /\.js$/,
exclude: [
path.resolve(__dirname, '')
],
enforce: 'post',
use: {
loader: WebpackObfuscator.loader,
}
}
]
},
plugins:[ plugins:[
new webpack.NoEmitOnErrorsPlugin(), new webpack.NoEmitOnErrorsPlugin(),
new CleanWebpackPlugin( {
root: resolve(""), // 设置根节点
verbose: true, //开启在控制台输出信息
dry: false,
}),
new WebpackObfuscator (ObfuscatorType), new WebpackObfuscator (ObfuscatorType),
] ]
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论