const path = require('path') const webpack = require('webpack') const buildDate = JSON.stringify(new Date().toLocaleString()) // const CompressionWebpackPlugin = require('compression-webpack-plugin') // const JavaScriptObfuscator = require('webpack-obfuscator') // const productionGzipExtensions = ['html', 'js', 'css'] function resolve (dir) { return path.join(__dirname, dir) } // vue.config.js const vueConfig = { pluginOptions: { electronBuilder: { nodeIntegration: true, //生成的生产环境构建文件的目录 // outputDir: 'jg-electron-app', nodeModulesPath: ['./node_modules'], // outputDir: 'electron_build', preload: { preload: 'src/preload.js' }, // "store” | “normal” | "maximum". - For testing builds, use 'store' to reduce build time significantly. // compression: 'store', // removePackageScripts: true, builderOptions: { electronDownload: { mirror: 'https://npm.taobao.org/mirrors/electron/' }, win: { icon: './src/assets/shortcut.ico', publisherName: 'lxp', target: [ 'nsis' ] }, linux: { icon: './src/assets/logo.ico', category: 'Utility', target: [ 'AppImage' ] }, mac: { icon: './src/assets/logo.ico', type: 'development', category: 'public.app-category.developer-tools', target: [ 'dmg' ] }, nsis: { include: './installer.nsh', allowToChangeInstallationDirectory: true, oneClick: false, // 是否为开始菜单快捷方式和程序文件目录创建子菜单 menuCategory: true, allowElevation: false, installerIcon: './src/assets/jgIcon.ico', uninstallerIcon: './src/assets/shortcut.ico', installerHeaderIcon: './src/assets/shortcut.ico', createDesktopShortcut: true, createStartMenuShortcut: true, deleteAppDataOnUninstall: true, // 将用于所有快捷方式的名称 shortcutName: 'JG-ADC工业生产监测系统', }, appId: 'com.lnjgkj', productName: 'JG-ADC工业生产监测系统', copyright: 'Copyright © 2022 辽宁津港科技技术部' }, } }, configureWebpack: { // webpack plugins plugins: [ // Ignore all locale files of moment.js new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), new webpack.DefinePlugin({ APP_VERSION: `"${require('./package.json').version}"`, BUILD_DATE: buildDate }), // 为生产环境修改配置... //开启gzip压缩,优化首屏加载速度 /*new CompressionWebpackPlugin({ algorithm: 'gzip', test: new RegExp( '\\.(' + productionGzipExtensions.join('|') + ')$' ), threshold: 10240, // 只有大小大于该值的资源会被处理 10240 minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理 deleteOriginalAssets: false // 删除原文件 }),*/ // js代码混淆 /*new JavaScriptObfuscator({ // 采用中度混淆 // // 压缩代码 // compact: true, // // 是否启用控制流扁平化(降低1.5倍的运行速度) // controlFlowFlattening: true, // // 应用概率;在较大的代码库中,建议降低此值,因为大量的控制流转换可能会增加代码的大小并降低代码的速度。 // controlFlowFlatteningThreshold: 0.75, // // 随机的死代码块(增加了混淆代码的大小) // deadCodeInjection: true, // // 死代码块的影响概率 // deadCodeInjectionThreshold: 0.4, // // 此选项几乎不可能使用开发者工具的控制台选项卡 // debugProtection: false, // // 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。 // debugProtectionInterval: 0, // // 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。 // disableConsoleOutput: true, // // 标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符) // identifierNamesGenerator: 'hexadecimal', // log: false, // // 是否启用全局变量和函数名称的混淆 // renameGlobals: false, // // 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意。 // rotateStringArray: true, // // 混淆后的代码,不能使用代码美化,同时需要配置 cpmpat:true; // selfDefending: true, // // 删除字符串文字并将它们放在一个特殊的数组中 // stringArray: true, // stringArrayEncoding: ['base64'], // stringArrayThreshold: 0.75, // transformObjectKeys: true, // // 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。 // unicodeEscapeSequence: false }, []),*/ ], //关闭性能提示 performance: { hints: false, maxEntrypointSize: 5000000, maxAssetSize: 3000000 }, externals: {}, }, devServer: { // development server port 8000 port: 8000, // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11 proxy: { '/api': { // target: 'http://192.168.1.130:5000', target: 'http://localhost:5000', // target: 'http://120.48.81.85:15002', pathRewrite: { '^/api': '' }, secure: false, ws: false, changeOrigin: true } } }, /* 通过 webpack-chain 维护webpack配置,这个库提供了一个 webpack 原始配置的上层抽象, 使其可以定义具名的 loader 规则和具名插件,并有机会在后期进入这些规则并对它们的选项进行修改。 通过链式操作,它允许我们更细粒度的控制其内部配置 */ chainWebpack: config => { config.resolve.alias.set('@$', resolve('src')) }, css: { loaderOptions: { less: { modifyVars: { 'border-radius-base': '2px' }, javascriptEnabled: true } } }, // babel-loader no-ignore node_modules/* transpileDependencies: [], runtimeCompiler: true, lintOnSave: false, //放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录 assetsDir: 'static', //生产环境关闭SourceMap,加速生产环境构建 productionSourceMap: false, } module.exports = vueConfig