vue.config.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const buildDate = JSON.stringify(new Date().toLocaleString())
  4. // const CompressionWebpackPlugin = require('compression-webpack-plugin')
  5. // const JavaScriptObfuscator = require('webpack-obfuscator')
  6. // const productionGzipExtensions = ['html', 'js', 'css']
  7. function resolve (dir) {
  8. return path.join(__dirname, dir)
  9. }
  10. // vue.config.js
  11. const vueConfig = {
  12. pluginOptions: {
  13. electronBuilder: {
  14. nodeIntegration: true,
  15. //生成的生产环境构建文件的目录
  16. // outputDir: 'jg-electron-app',
  17. nodeModulesPath: ['./node_modules'],
  18. // outputDir: 'electron_build',
  19. preload: { preload: 'src/preload.js' },
  20. // "store” | “normal” | "maximum". - For testing builds, use 'store' to reduce build time significantly.
  21. // compression: 'store',
  22. // removePackageScripts: true,
  23. builderOptions: {
  24. electronDownload: {
  25. mirror: 'https://npm.taobao.org/mirrors/electron/'
  26. },
  27. win: {
  28. icon: './src/assets/shortcut.ico',
  29. publisherName: 'lxp',
  30. target: [
  31. 'nsis'
  32. ]
  33. },
  34. linux: {
  35. icon: './src/assets/logo.ico',
  36. category: 'Utility',
  37. target: [
  38. 'AppImage'
  39. ]
  40. },
  41. mac: {
  42. icon: './src/assets/logo.ico',
  43. type: 'development',
  44. category: 'public.app-category.developer-tools',
  45. target: [
  46. 'dmg'
  47. ]
  48. },
  49. nsis: {
  50. include: './installer.nsh',
  51. allowToChangeInstallationDirectory: true,
  52. oneClick: false,
  53. // 是否为开始菜单快捷方式和程序文件目录创建子菜单
  54. menuCategory: true,
  55. allowElevation: false,
  56. installerIcon: './src/assets/jgIcon.ico',
  57. uninstallerIcon: './src/assets/shortcut.ico',
  58. installerHeaderIcon: './src/assets/shortcut.ico',
  59. createDesktopShortcut: true,
  60. createStartMenuShortcut: true,
  61. deleteAppDataOnUninstall: true,
  62. // 将用于所有快捷方式的名称
  63. shortcutName: 'JG-ADC工业生产监测系统',
  64. },
  65. appId: 'com.lnjgkj',
  66. productName: 'JG-ADC工业生产监测系统',
  67. copyright: 'Copyright © 2022 辽宁津港科技技术部'
  68. },
  69. }
  70. },
  71. configureWebpack: {
  72. // webpack plugins
  73. plugins: [
  74. // Ignore all locale files of moment.js
  75. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  76. new webpack.DefinePlugin({
  77. APP_VERSION: `"${require('./package.json').version}"`,
  78. BUILD_DATE: buildDate
  79. }),
  80. // 为生产环境修改配置...
  81. //开启gzip压缩,优化首屏加载速度
  82. /*new CompressionWebpackPlugin({
  83. algorithm: 'gzip',
  84. test: new RegExp(
  85. '\\.(' + productionGzipExtensions.join('|') + ')$'
  86. ),
  87. threshold: 10240, // 只有大小大于该值的资源会被处理 10240
  88. minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
  89. deleteOriginalAssets: false // 删除原文件
  90. }),*/
  91. // js代码混淆
  92. /*new JavaScriptObfuscator({
  93. // 采用中度混淆
  94. // // 压缩代码
  95. // compact: true,
  96. // // 是否启用控制流扁平化(降低1.5倍的运行速度)
  97. // controlFlowFlattening: true,
  98. // // 应用概率;在较大的代码库中,建议降低此值,因为大量的控制流转换可能会增加代码的大小并降低代码的速度。
  99. // controlFlowFlatteningThreshold: 0.75,
  100. // // 随机的死代码块(增加了混淆代码的大小)
  101. // deadCodeInjection: true,
  102. // // 死代码块的影响概率
  103. // deadCodeInjectionThreshold: 0.4,
  104. // // 此选项几乎不可能使用开发者工具的控制台选项卡
  105. // debugProtection: false,
  106. // // 如果选中,则会在“控制台”选项卡上使用间隔强制调试模式,从而更难使用“开发人员工具”的其他功能。
  107. // debugProtectionInterval: 0,
  108. // // 通过用空函数替换它们来禁用console.log,console.info,console.error和console.warn。这使得调试器的使用更加困难。
  109. // disableConsoleOutput: true,
  110. // // 标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符)
  111. // identifierNamesGenerator: 'hexadecimal',
  112. // log: false,
  113. // // 是否启用全局变量和函数名称的混淆
  114. // renameGlobals: false,
  115. // // 通过固定和随机(在代码混淆时生成)的位置移动数组。这使得将删除的字符串的顺序与其原始位置相匹配变得更加困难。如果原始源代码不小,建议使用此选项,因为辅助函数可以引起注意。
  116. // rotateStringArray: true,
  117. // // 混淆后的代码,不能使用代码美化,同时需要配置 cpmpat:true;
  118. // selfDefending: true,
  119. // // 删除字符串文字并将它们放在一个特殊的数组中
  120. // stringArray: true,
  121. // stringArrayEncoding: ['base64'],
  122. // stringArrayThreshold: 0.75,
  123. // transformObjectKeys: true,
  124. // // 允许启用/禁用字符串转换为unicode转义序列。Unicode转义序列大大增加了代码大小,并且可以轻松地将字符串恢复为原始视图。建议仅对小型源代码启用此选项。
  125. // unicodeEscapeSequence: false
  126. }, []),*/
  127. ],
  128. //关闭性能提示
  129. performance: {
  130. hints: false,
  131. maxEntrypointSize: 5000000,
  132. maxAssetSize: 3000000
  133. },
  134. externals: {},
  135. },
  136. devServer: {
  137. // development server port 8000
  138. port: 8000,
  139. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  140. proxy: {
  141. '/api': {
  142. // target: 'http://192.168.1.130:5000',
  143. target: 'http://localhost:5000',
  144. // target: 'http://117.62.238.129:5000',
  145. // target: 'http://192.168.50.126:5000',
  146. // target: 'http://120.48.81.85:15002',
  147. pathRewrite: { '^/api': '' },
  148. secure: false,
  149. ws: false,
  150. changeOrigin: true
  151. }
  152. }
  153. },
  154. /* 通过 webpack-chain 维护webpack配置,这个库提供了一个 webpack 原始配置的上层抽象,
  155. 使其可以定义具名的 loader 规则和具名插件,并有机会在后期进入这些规则并对它们的选项进行修改。
  156. 通过链式操作,它允许我们更细粒度的控制其内部配置 */
  157. chainWebpack: config => {
  158. config.resolve.alias.set('@$', resolve('src'))
  159. },
  160. css: {
  161. loaderOptions: {
  162. less: {
  163. modifyVars: {
  164. 'border-radius-base': '2px'
  165. },
  166. javascriptEnabled: true
  167. }
  168. }
  169. },
  170. // babel-loader no-ignore node_modules/*
  171. transpileDependencies: [],
  172. runtimeCompiler: true,
  173. lintOnSave: false,
  174. //放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  175. assetsDir: 'static',
  176. //生产环境关闭SourceMap,加速生产环境构建
  177. productionSourceMap: false,
  178. }
  179. module.exports = vueConfig