#独家
vite 项目混淆加密 怎么配置?

2023-05-08 0 2,869

vite 项目混淆加密 怎么配置?下面这样配置会报错caught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../".
想要只在生产环境build添加加密,应该怎么写呢?

  build: {
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue', 'jquery'],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: 'Vue',
          jquery: '$'
        }
      },
      plugins: [
        obfuscator({
          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,
        }),
      ],
    },
  },
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import javascriptObfuscator from 'rollup-plugin-javascript-obfuscator'

// 配置
export default defineConfig(({ command }) => ({
  plugins: [
    vue(),
    command === 'build' && 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,
    })
  ].filter(Boolean),
  build: {
    rollupOptions: {
      external: ['vue', 'jquery'],
      output: {
        globals: {
          vue: 'Vue',
          jquery: '$'
        }
      },
    },
  },
}))
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

1. JK下载官网所有资源来源于开发团队,加入会员即可下载使用!如有问题请联系右下角在线客服!
2. JK下载官方保障所有软件都通过人工亲测,为每位会员用户提供安全可靠的应用软件、游戏资源下载及程序开发服务。
3. JK开发团队针对会员诉求,历经多年拥有现今开发成果, 每款应用程序上线前都经过人工测试无误后提供安装使用,只为会员提供安全原创的应用。
4. PC/移动端应用下载后如遇安装使用问题请联系右下角在线客服或提交工单,一对一指导解决疑难。

JK软件下载官网 技术分享 vite 项目混淆加密 怎么配置? https://www.jkxiazai.com/1699.html

JK软件应用商店是经过官方安全认证,保障正版软件平台

相关资源

官方客服团队

为您解决烦忧 - 24小时在线 专业服务