vue.config.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. 'use strict'
  2. const path = require('path')
  3. // const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. // const name = defaultSettings.title || 'VVM' // 标题
  8. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  9. // vue.config.js 配置说明
  10. //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
  11. // 这里只列一部分,具体配置参考文档
  12. module.exports = {
  13. // 部署生产环境和开发环境下的URL。
  14. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  15. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  16. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  17. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  18. outputDir: "dist",
  19. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  20. assetsDir: 'static',
  21. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  22. lintOnSave: false,
  23. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  24. productionSourceMap: false,
  25. // webpack-dev-server 相关配置
  26. devServer: {
  27. host: '0.0.0.0',
  28. port: port,
  29. open: true,
  30. proxy: {
  31. // detail: https://cli.vuejs.org/config/#devserver-proxy
  32. [process.env.VUE_APP_BASE_API]: {
  33. // target: `http://monitor.vandh.org:88`,
  34. // target: `http://192.168.2.112:81/`,
  35. // target:`http://124.70.8.54:82/`,
  36. target: `http://evvmapi.vandh.org/`,
  37. changeOrigin: true,
  38. pathRewrite: {
  39. ['^' + process.env.VUE_APP_BASE_API]: ''
  40. }
  41. },
  42. '/api': {
  43. // target:'http://192.168.2.112:9000/',
  44. target: 'http://localhost:9000/',
  45. changeOrigin: true,
  46. pathRewrite: {
  47. '/api': ''
  48. }
  49. },
  50. // '/bpi': {
  51. // target: 'https://api.map.baidu.com/',
  52. // changeOrigin: true,
  53. // pathRewrite: {
  54. // '/bpi': ''
  55. // }
  56. // },
  57. },
  58. disableHostCheck: true
  59. },
  60. configureWebpack: {
  61. // name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src'),
  65. 'vue$': 'vue/dist/vue.esm.js'
  66. }
  67. }
  68. },
  69. chainWebpack(config) {
  70. config.plugins.delete('preload') // TODO: need test
  71. config.plugins.delete('prefetch') // TODO: need test
  72. // set svg-sprite-loader
  73. config.module
  74. .rule('svg')
  75. .exclude.add(resolve('src/assets/icons'))
  76. .end()
  77. config.module
  78. .rule('icons')
  79. .test(/\.svg$/)
  80. .include.add(resolve('src/assets/icons'))
  81. .end()
  82. .use('svg-sprite-loader')
  83. .loader('svg-sprite-loader')
  84. .options({
  85. symbolId: 'icon-[name]'
  86. })
  87. .end()
  88. config
  89. .when(process.env.NODE_ENV !== 'development',
  90. config => {
  91. config
  92. .plugin('ScriptExtHtmlWebpackPlugin')
  93. .after('html')
  94. .use('script-ext-html-webpack-plugin', [{
  95. // `runtime` must same as runtimeChunk name. default is `runtime`
  96. inline: /runtime\..*\.js$/
  97. }])
  98. .end()
  99. config
  100. .optimization.splitChunks({
  101. chunks: 'all',
  102. cacheGroups: {
  103. libs: {
  104. name: 'chunk-libs',
  105. test: /[\\/]node_modules[\\/]/,
  106. priority: 10,
  107. chunks: 'initial' // only package third parties that are initially dependent
  108. },
  109. elementUI: {
  110. name: 'chunk-elementUI', // split elementUI into a single package
  111. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  112. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  113. },
  114. commons: {
  115. name: 'chunk-commons',
  116. test: resolve('src/components'), // can customize your rules
  117. minChunks: 3, // minimum common number
  118. priority: 5,
  119. reuseExistingChunk: true
  120. }
  121. }
  122. })
  123. config.optimization.runtimeChunk('single'),
  124. {
  125. from: path.resolve(__dirname, './public/robots.txt'),//防爬虫文件
  126. to: './',//到根目录下
  127. }
  128. }
  129. )
  130. },
  131. pluginOptions: {
  132. // vue-cli-plugin-electron-builder 配置
  133. electronBuilder: {
  134. nodeIntegration: true,
  135. builderOptions: {
  136. // 设置打包之后的应用名称
  137. productName: '产品出场检测',
  138. win: {
  139. icon: 'public/favicon.ico',
  140. // 图标路径 windows系统中icon需要256*256的ico格式图片,更换应用图标亦在此处
  141. target: [{
  142. // 打包成一个独立的 exe 安装程序
  143. target: 'nsis',
  144. // 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大
  145. arch: [
  146. 'x64'
  147. // 'ia32'
  148. ]
  149. }]
  150. },
  151. dmg: {
  152. contents: [
  153. {
  154. x: 410,
  155. y: 150,
  156. type: 'link',
  157. path: '/Applications'
  158. },
  159. {
  160. x: 130,
  161. y: 150,
  162. type: 'file'
  163. }
  164. ]
  165. },
  166. linux: {
  167. // 设置linux的图标
  168. icon: 'public/favicon.ico',
  169. target: 'AppImage'
  170. },
  171. mac: {
  172. icon: 'public/favicon.ico'
  173. },
  174. files: ['**/*'],
  175. extraResources: {
  176. // 拷贝dll等静态文件到指定位置,否则打包之后回出现找不大dll的问题
  177. from: 'resources/',
  178. to: './'
  179. },
  180. asar: false,
  181. nsis: {
  182. // 是否一键安装,建议为 false,可以让用户点击下一步、下一步、下一步的形式安装程序,如果为true,当用户双击构建好的程序,自动安装程序并打开,即:一键安装(one-click installer)
  183. oneClick: false,
  184. // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
  185. allowElevation: true,
  186. // 允许修改安装目录,建议为 true,是否允许用户改变安装目录,默认是不允许
  187. allowToChangeInstallationDirectory: true,
  188. // 安装图标
  189. installerIcon: 'public/favicon.ico',
  190. // 卸载图标
  191. uninstallerIcon: 'public/favicon.ico',
  192. // 安装时头部图标
  193. installerHeaderIcon: 'public/favicon.ico',
  194. // 创建桌面图标
  195. createDesktopShortcut: true,
  196. // 创建开始菜单图标
  197. createStartMenuShortcut: true
  198. }
  199. },
  200. chainWebpackMainProcess: config => {
  201. config.plugin('define').tap(args => {
  202. args[0].IS_ELECTRON = true
  203. return args
  204. })
  205. },
  206. chainWebpackRendererProcess: config => {
  207. config.plugin('define').tap(args => {
  208. args[0].IS_ELECTRON = true
  209. return args
  210. })
  211. }
  212. }
  213. }
  214. }