getkey / rollup-plugin-obfuscator

The most powerful rollup plugin for javascript-obfuscator.
Mozilla Public License 2.0
121 stars 9 forks source link

Vite+Vue3 If global is set to false, Identifier "createApp" has already been declared. #24

Open wenyongda opened 11 months ago

wenyongda commented 11 months ago

Describe the bug

If global is set to false, Identifier "createApp" has already been declared.

To Reproduce

1.global is set to false 2.build the project 3.Identifier "createApp" has already been declared

Stack trace

[javascript-obfuscator] Obfuscation completed. Total time: 0.2 sec.
Identifier "createApp" has already been declared
file: E:/JumpPwd-chrome-extension/src/entries/popup/main.ts:1:9
1: import { createApp } from "vue";
            ^
2: import "@/style.css";
3: import App from "./App.vue";
error during build:
RollupError: Identifier "createApp" has already been declared
    at error (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/parseAst.js
:337:30)
    at Module.error (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/node
-entry.js:12738:16)
    at Module.addImport (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/
node-entry.js:13288:22)
    at ImportDeclaration.initialise (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dis
t/es/shared/node-entry.js:9953:28)
    at new NodeBase (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/node
-entry.js:4607:14)
    at new ImportDeclaration (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/sh
ared/node-entry.js:9946:1)
    at Program.parseNode (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared
/node-entry.js:4718:27)
    at new NodeBase (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/node
-entry.js:4606:14)
    at new Program (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/node-
entry.js:10967:9)
    at Module.setSource (file:///E:/JumpPwd-chrome-extension/node_modules/rollup/dist/es/shared/
node-entry.js:13119:20)
error Command failed with exit code 1.

Package versions:

Additional context Add any other context about the problem here. import { resolve, dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import webExtension from "@samrum/vite-plugin-web-extension"; import manifest from "./src/manifest"; import AutoImport from "unplugin-auto-import/vite"; import Components from "unplugin-vue-components/vite"; import { NaiveUiResolver } from "unplugin-vue-components/resolvers"; import obfuscator from "rollup-plugin-obfuscator";

const __dirname = dirname(fileURLToPath(import.meta.url));

// https://vitejs.dev/config/ export default defineConfig({ build: { minify: "esbuild", // 默认 }, // esbuild: { // drop: ["console", "debugger"], //打包去除 // }, resolve: { alias: { "@": resolve(__dirname, "src"), }, }, server: { port: 9999, }, plugins: [ vue(), webExtension({ manifest: { ...manifest, }, }), AutoImport({ dts: "src/auto-imports.d.ts", imports: [ "vue", { "naive-ui": [ "useDialog", "useMessage", "useNotification", "useLoadingBar", ], }, "@vueuse/core", ], }), Components({ resolvers: [NaiveUiResolver()], }), obfuscator({ global: false, // options配置项实际为 javascript-obfuscator 选项,具体可查看https://github.com/javascript-obfuscator/javascript-obfuscator options: { compact: true, controlFlowFlattening: true, controlFlowFlatteningThreshold: 0.75, numbersToExpressions: true, simplify: true, stringArrayShuffle: true, splitStrings: true, splitStringsChunkLength: 10, rotateUnicodeArray: true, deadCodeInjection: true, deadCodeInjectionThreshold: 0.4, debugProtection: false, debugProtectionInterval: 2000, disableConsoleOutput: true, domainLock: [], identifierNamesGenerator: "hexadecimal", identifiersPrefix: "", inputFileName: "", log: true, renameGlobals: true, reservedNames: [], reservedStrings: [], seed: 0, selfDefending: true, sourceMap: false, sourceMapBaseUrl: "", sourceMapFileName: "", sourceMapMode: "separate", stringArray: true, stringArrayEncoding: ["base64"], stringArrayThreshold: 0.75, target: "browser", transformObjectKeys: true, unicodeEscapeSequence: true, domainLockRedirectUrl: "about:blank", forceTransformStrings: [], identifierNamesCache: null, identifiersDictionary: [], ignoreImports: true, optionsPreset: "default", renameProperties: false, renamePropertiesMode: "safe", sourceMapSourcesMode: "sources-content",

    stringArrayCallsTransform: true,
    stringArrayCallsTransformThreshold: 0.5,

    stringArrayIndexesType: ["hexadecimal-number"],
    stringArrayIndexShift: true,
    stringArrayRotate: true,
    stringArrayWrappersCount: 1,
    stringArrayWrappersChainedCalls: true,
    stringArrayWrappersParametersMaxCount: 2,
    stringArrayWrappersType: "variable",
    include: ["src/components/BuildPwd.vue"],
  },
}),

], });

YvesChen commented 6 months ago

去掉vite.config.ts里面的配置


obfuscator->options->disableConsoleOutput:true
这个配置去掉

package.json:


"javascript-obfuscator": "^4.1.0",
"rollup-plugin-obfuscator": "^1.1.0",

关键代码

window.onload = () => {
  import('vue').then(Vue => {
    const { createApp } = Vue;
  })
}