vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const { CleanWebpackPlugin } = require('clean-webpack-plugin')
  5. const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || 'ISMS' // page title
  10. // If your port is set to 80,
  11. // use administrator privileges to execute the command line.
  12. // For example, Mac: sudo npm run
  13. // You can change the port by the following methods:
  14. // port = 9528 npm run dev OR npm run dev --port = 9528
  15. const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  16. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  17. module.exports = {
  18. /**
  19. * You will need to set publicPath if you plan to deploy your site under a sub path,
  20. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  21. * then publicPath should be set to "/bar/".
  22. * In most cases please use '/' !!!
  23. * Detail: https://cli.vuejs.org/config/#publicpath
  24. */
  25. publicPath: '/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. // lintOnSave: process.env.NODE_ENV === 'development',
  29. lintOnSave: false, // 关闭eslint检查
  30. productionSourceMap: false,
  31. devServer: {
  32. port: port,
  33. open: true,
  34. overlay: {
  35. warnings: false,
  36. errors: true,
  37. },
  38. proxy: {
  39. [process.env.VUE_APP_BASE_API]: {
  40. // target: 'http://39.101.177.49:5011/mock/11', //远程yapi
  41. // target: 'http://39.101.177.49:5014/yapi', // 远程服务器-皞哥
  42. // target: 'http://10.168.239.123:20001', // 皞哥服务器
  43. // target: 'http://10.130.1.251:5002', // 远程服务器
  44. // target: 'http://localhost:5002', // localhost
  45. // target: 'http://localhost:18908', // 宝莫穿透
  46. // target: 'http://192.168.18.221:8080/prod-api/', // 巡检模块Demo
  47. // target: 'http://192.168.18.200:18082/prod-api/', // 巡检模块Demo
  48. // target: 'http://192.168.18.200:8080/prod-api/', // 巡检模块Demo
  49. // target: "http://172.16.214.237:8080/prod-api/", // 远程服务器-赵哥
  50. // target: "http://39.101.177.49:5012", // 远程服务器-皞哥
  51. // target: 'http://10.168.239.129:6002', // 118现场服务器
  52. // target: 'http://192.168.70.11:8080/prod-api/', //静海现场
  53. target: 'http://192.168.195.129:8080/prod-api/', //本地虚拟
  54. changeOrigin: true,
  55. pathRewrite: {
  56. '^/dev-api': '',
  57. },
  58. },
  59. },
  60. // before: require('./mock/mock-server.js')
  61. },
  62. configureWebpack: {
  63. // provide the app's title in webpack's name field, so that
  64. // it can be accessed in index.html to inject the correct title.
  65. name: name,
  66. resolve: {
  67. alias: {
  68. '@': resolve('src'),
  69. '@crud': resolve('src/components/Crud'),
  70. },
  71. },
  72. },
  73. chainWebpack(config) {
  74. // config.plugin('cache').use(HardSourceWebpackPlugin)
  75. // it can improve the speed of the first screen, it is recommended to turn on preload
  76. config.plugin('preload').tap(() => [
  77. {
  78. rel: 'preload',
  79. // to ignore runtime.js
  80. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  81. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  82. include: 'initial',
  83. },
  84. ])
  85. // when there are many pages, it will cause too many meaningless requests
  86. config.plugins.delete('prefetch')
  87. // set svg-sprite-loader
  88. config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
  89. config.module
  90. .rule('icons')
  91. .test(/\.svg$/)
  92. .include.add(resolve('src/assets/icons'))
  93. .end()
  94. .use('svg-sprite-loader')
  95. .loader('svg-sprite-loader')
  96. .options({
  97. symbolId: 'icon-[name]',
  98. })
  99. .end()
  100. // set preserveWhitespace
  101. config.module
  102. .rule('vue')
  103. .use('vue-loader')
  104. .loader('vue-loader')
  105. .tap((options) => {
  106. options.compilerOptions.preserveWhitespace = true
  107. return options
  108. })
  109. .end()
  110. config.when(process.env.NODE_ENV !== 'development', (config) => {
  111. config
  112. .plugin('ScriptExtHtmlWebpackPlugin')
  113. .after('html')
  114. .use('script-ext-html-webpack-plugin', [
  115. {
  116. // `runtime` must same as runtimeChunk name. default is `runtime`
  117. inline: /runtime\..*\.js$/,
  118. },
  119. ])
  120. .end()
  121. config.optimization.splitChunks({
  122. chunks: 'all',
  123. cacheGroups: {
  124. libs: {
  125. name: 'chunk-libs',
  126. test: /[\\/]node_modules[\\/]/,
  127. priority: 10,
  128. chunks: 'initial', // only package third parties that are initially dependent
  129. },
  130. elementUI: {
  131. name: 'chunk-elementUI', // split elementUI into a single package
  132. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  133. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  134. },
  135. commons: {
  136. name: 'chunk-commons',
  137. test: resolve('src/components'), // can customize your rules
  138. minChunks: 3, // minimum common number
  139. priority: 5,
  140. reuseExistingChunk: true,
  141. },
  142. },
  143. })
  144. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  145. config.optimization.runtimeChunk('single')
  146. // 删除设置文件夹,防止覆盖
  147. config.plugin('CleanWebpackPlugin').use(CleanWebpackPlugin, [
  148. {
  149. cleanAfterEveryBuildPatterns: ['static/setting*'],
  150. },
  151. ])
  152. })
  153. },
  154. transpileDependencies: [/\/node_modules\/vue-echarts\//, /\/node_modules\/resize-detector\//],
  155. }