import { defineConfig, loadEnv } from "vite"; import vue from "@vitejs/plugin-vue"; import Components from "unplugin-vue-components/vite"; import { NaiveUiResolver } from "unplugin-vue-components/resolvers"; import AutoImport from "unplugin-auto-import/vite"; import legacy from "@vitejs/plugin-legacy"; import vueJsx from "@vitejs/plugin-vue-jsx"; // import obfuscator from "rollup-plugin-obfuscator"; const env = loadEnv("development", process.cwd(), ""); const path = require("path"); const disableObfuse = process.env.DISABLE_OBFUSE; // console.log(process.env); // console.log(disableObfuse); console.log("process.env.DISABLE_OBFUSE: ", disableObfuse); // https://vitejs.dev/config/ export default defineConfig({ base: "/oe-web/", plugins: [ vue({ reactivityTransform: true }), vueJsx({}), Components({ resolvers: [NaiveUiResolver()], dts: "src/types/components.d.ts", }), AutoImport({ // targets to transform include: [ /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx /\.vue$/, /\.vue\?vue/, // .vue ], resolvers: [(name) => (name === "logger" ? "@/utils/logger" : undefined)], dts: "src/types/auto-imports.d.ts", // Generate corresponding .eslintrc-auto-import.json file. // eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals eslintrc: { enabled: true, // Default `false` filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json` globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable') }, }), legacy({ targets: ["chrome >= 58"], additionalLegacyPolyfills: ["regenerator-runtime/runtime"], }), // process.env.NODE_ENV === "development" // ? {} // : // : obfuscator({ // // 不同的构建可能成功运行也可能不成功? // // 看看是不是单个文件做transform,然后对最终文件做renderChunk导致的构建结果不一致 // fileOptions: false, // // fileOptions: { // // optionsPreset: "low-obfuscation", // // debugProtection: false, // // transformObjectKeys: false, // // disableConsoleOutput: false, // // // controlFlowFlattening: true, // // controlFlowFlatteningThreshold: 0.9, // // // per-file: // // deadCodeInjection: true, // // deadCodeInjectionThreshold: 1, // // // stringArrayThreshold: 1, // // // numbersToExpressions: true, // // // controlFlowFlatteningThreshold: 1, // // // stringArrayCallsTransform: true, // // // stringArrayCallsTransformThreshold: 1, // // // stringArrayEncoding: ["rc4"], // // }, // globalOptions: { // optionsPreset: "low-obfuscation", // // debugProtection: true, // // debugProtectionInterval: 2000, // // domainLock: [ // // ".exam-cloud.cn", // // ".test41v3.qmth.com.cn", // // ".ea100.com.cn", // // ".ecs.qmth.com.cn", // // ".qmth.com.cn", // // ".dev39.qmth.com.cn", // // ".test41.qmth.com.cn", // // ], // domainLock: [], // // selfDefending: true, // // sourceMap: false, // // splitStrings: true, // disableConsoleOutput: false, // // // stringArrayCallsTransform: true, // // deadCodeInjection: true, // // numbersToExpressions: true, // controlFlowFlattening: true, // // stringArrayEncoding: ["none", "base64", "rc4"], // // stringArrayRotate: true, // // transformObjectKeys: true, // }, // include: [ // // "src/**/**.ts", // // "src/**/**.js", // "src/utils/**.ts", // // "**/UserLogin/**.ts", // // "**/Examing/**/**.ts", // ], // exclude: ["node_modules/**"], // ...(disableObfuse // ? { // fileOptions: false, // globalOptions: false, // } // : {}), // }), // javascriptObfuscator({ // compact: true, // controlFlowFlattening: true, // controlFlowFlatteningThreshold: 1, // deadCodeInjection: true, // deadCodeInjectionThreshold: 1, // debugProtection: true, // debugProtectionInterval: 0, // disableConsoleOutput: true, // identifierNamesGenerator: "hexadecimal", // log: false, // renameGlobals: false, // rotateStringArray: true, // selfDefending: true, // shuffleStringArray: true, // splitStrings: true, // splitStringsChunkLength: 10, // stringArray: true, // stringArrayEncoding: ["rc4"], // stringArrayThreshold: 1, // transformObjectKeys: true, // unicodeEscapeSequence: false, // }), ], server: { port: 9030, // strictPort: true, fs: { strict: true, allow: ["./"], }, proxy: { "/api": { target: env.VUE_APP_DEV_PROXY, changeOrigin: true, secure: false, ws: false, }, "/admin": { target: env.VUE_APP_DEV_PROXY, changeOrigin: true, secure: false, }, }, }, resolve: { alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }], extensions: [ ".js", ".mjs", ".ts", ".tsx", ".vue", ".json", ".scss", ".css", ], }, build: { ssr: false, // FIXME: 为初期测试开启的调试 sourcemap: !!disableObfuse, target: ["chrome58"], }, // define: { // __VUE_PROD_DEVTOOLS__: true, // no effect // }, });