vue-cli-plugin-javascript-obfuscator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/index.js +116 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 nangongpo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# vue-cli-plugin-javascript-obfuscator
|
|
2
|
+
|
|
3
|
+
A Vue CLI plugin to automatically obfuscate JavaScript files using `javascript-obfuscator@4.x`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the plugin, run the following command:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
vue add javascript-obfuscator
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
After installing the plugin, you can configure it in your vue.config.js file under the pluginOptions field.
|
|
17
|
+
|
|
18
|
+
Example Configuration:
|
|
19
|
+
```
|
|
20
|
+
// vue.config.js
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
pluginOptions: {
|
|
24
|
+
javascriptObfuscator: {
|
|
25
|
+
// Directory where your assets are located (default is 'static')
|
|
26
|
+
assetsDir: 'static', // Optional, defaults to 'static'
|
|
27
|
+
|
|
28
|
+
// Files to include in obfuscation (can be a string or an array of strings/regex patterns)
|
|
29
|
+
includes: [
|
|
30
|
+
'app.*.js',
|
|
31
|
+
'**/chunk-libs.*.js$', // Matches chunk-libs files for obfuscation
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// Files to exclude from obfuscation (can be a string or an array of strings/regex patterns)
|
|
35
|
+
excludes: [
|
|
36
|
+
'vendor.*.js',
|
|
37
|
+
'**/*-bundle.*.js$', // Matches any file ending with -bundle for exclusion
|
|
38
|
+
],
|
|
39
|
+
|
|
40
|
+
// Options for the javascript-obfuscator
|
|
41
|
+
obfuscatorOptions: {
|
|
42
|
+
compact: true, // Minify the code
|
|
43
|
+
disableConsoleOutput: false, // Keep console output
|
|
44
|
+
rotateStringArray: true, // Rotate the string array during obfuscation
|
|
45
|
+
identifierNamesGenerator: 'hexadecimal', // Use hexadecimal naming for identifiers
|
|
46
|
+
selfDefending: true, // Make the obfuscated code harder to read
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const JavaScriptObfuscator = require('javascript-obfuscator')
|
|
3
|
+
|
|
4
|
+
module.exports = (api) => {
|
|
5
|
+
// Automatically install javascript-obfuscator@4.x when the plugin is added
|
|
6
|
+
api.extendPackage({
|
|
7
|
+
devDependencies: {
|
|
8
|
+
'javascript-obfuscator': '^4.0.0' // Automatically add version 4.x
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// Inject a feature for the plugin
|
|
13
|
+
api.injectFeature({
|
|
14
|
+
name: 'javascript-obfuscator',
|
|
15
|
+
description:
|
|
16
|
+
'A plugin to obfuscate JavaScript files using javascript-obfuscator',
|
|
17
|
+
enabled: true
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Vue CLI chainWebpack hook to apply the JavaScript Obfuscator plugin.
|
|
22
|
+
* @param {object} config - The Webpack configuration object.
|
|
23
|
+
*/
|
|
24
|
+
api.chainWebpack((config) => {
|
|
25
|
+
// Get user-configured options from vue.config.js
|
|
26
|
+
const options =
|
|
27
|
+
api.service.projectOptions.pluginOptions.javascriptObfuscator || {}
|
|
28
|
+
|
|
29
|
+
// Default values for the plugin options
|
|
30
|
+
const assetsDir = options.assetsDir || 'static'
|
|
31
|
+
const includes = Array.isArray(options.includes)
|
|
32
|
+
? options.includes
|
|
33
|
+
: [options.includes || []]
|
|
34
|
+
const excludes = Array.isArray(options.excludes)
|
|
35
|
+
? options.excludes
|
|
36
|
+
: [options.excludes || []]
|
|
37
|
+
const obfuscatorOptions = options.obfuscatorOptions || {}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Webpack plugin that obfuscates JavaScript assets.
|
|
41
|
+
* @param {object} compiler - Webpack compiler instance
|
|
42
|
+
*/
|
|
43
|
+
function JavascriptObfuscatorPlugin(compiler) {
|
|
44
|
+
compiler.hooks.emit.tapAsync(
|
|
45
|
+
'JavascriptObfuscatorPlugin',
|
|
46
|
+
async (compilation, callback) => {
|
|
47
|
+
const promises = []
|
|
48
|
+
|
|
49
|
+
// Generate regex patterns from includes and excludes
|
|
50
|
+
const includePatterns = includes.map((pattern) =>
|
|
51
|
+
typeof pattern === 'string'
|
|
52
|
+
? new RegExp(pattern.replace('static', assetsDir))
|
|
53
|
+
: pattern
|
|
54
|
+
)
|
|
55
|
+
const excludePatterns = excludes.map((pattern) =>
|
|
56
|
+
typeof pattern === 'string'
|
|
57
|
+
? new RegExp(pattern.replace('static', assetsDir))
|
|
58
|
+
: pattern
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
Object.keys(compilation.assets).forEach((assetName) => {
|
|
62
|
+
// Skip assets that don't match the include or match any of the exclude patterns
|
|
63
|
+
if (
|
|
64
|
+
includePatterns.length &&
|
|
65
|
+
!includePatterns.some((pattern) => pattern.test(assetName))
|
|
66
|
+
) {
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (excludePatterns.some((pattern) => pattern.test(assetName))) {
|
|
71
|
+
console.log(`Skipping obfuscation for: ${assetName}`)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log(`Obfuscating: ${assetName}`)
|
|
76
|
+
const asset = compilation.assets[assetName]
|
|
77
|
+
promises.push(
|
|
78
|
+
new Promise((resolve, reject) => {
|
|
79
|
+
try {
|
|
80
|
+
const obfuscated = JavaScriptObfuscator.obfuscate(
|
|
81
|
+
asset.source(),
|
|
82
|
+
{
|
|
83
|
+
compact: true,
|
|
84
|
+
disableConsoleOutput: false,
|
|
85
|
+
rotateStringArray: true,
|
|
86
|
+
identifierNamesGenerator: 'hexadecimal',
|
|
87
|
+
selfDefending: true,
|
|
88
|
+
...obfuscatorOptions // Spread any additional options
|
|
89
|
+
}
|
|
90
|
+
).getObfuscatedCode()
|
|
91
|
+
|
|
92
|
+
compilation.assets[assetName] = {
|
|
93
|
+
source: () => obfuscated,
|
|
94
|
+
size: () => obfuscated.length
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
resolve()
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error(`Failed to obfuscate ${assetName}:`, err)
|
|
100
|
+
reject(err) // Reject if there's an error in obfuscation
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Wait for all files to be processed
|
|
107
|
+
await Promise.all(promises)
|
|
108
|
+
callback()
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Instantiate and apply the plugin to the Webpack config
|
|
114
|
+
config.plugin('javascript-obfuscator').use(JavascriptObfuscatorPlugin)
|
|
115
|
+
})
|
|
116
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-cli-plugin-javascript-obfuscator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue CLI plugin for JavaScript obfuscation using javascript-obfuscator@4.x",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/nangongpo/vue-cli-plugin-javascript-obfuscator.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vue",
|
|
15
|
+
"vue-cli",
|
|
16
|
+
"javascript-obfuscator"
|
|
17
|
+
],
|
|
18
|
+
"author": "nangongpo",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/nangongpo/vue-cli-plugin-javascript-obfuscator/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/nangongpo/vue-cli-plugin-javascript-obfuscator#readme",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"javascript-obfuscator": "^4.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|