vue.config.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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://172.16.214.237:8080/prod-api/", // 远程服务器-赵哥
  49. // target: "http://39.101.177.49:5012", // 远程服务器-皞哥
  50. // target: 'http://10.168.239.129:6002', // 118现场服务器
  51. // target: 'http://192.168.70.11:8080/prod-api/', //静海现场
  52. target: 'http://192.168.195.129:8080/prod-api/', //静海现场
  53. changeOrigin: true,
  54. pathRewrite: {
  55. '^/dev-api': '',
  56. },
  57. },
  58. },
  59. // before: require('./mock/mock-server.js')
  60. },
  61. configureWebpack: {
  62. // provide the app's title in webpack's name field, so that
  63. // it can be accessed in index.html to inject the correct title.
  64. name: name,
  65. resolve: {
  66. alias: {
  67. '@': resolve('src'),
  68. '@crud': resolve('src/components/Crud'),
  69. },
  70. },
  71. },
  72. chainWebpack(config) {
  73. // config.plugin('cache').use(HardSourceWebpackPlugin)
  74. // it can improve the speed of the first screen, it is recommended to turn on preload
  75. config.plugin('preload').tap(() => [
  76. {
  77. rel: 'preload',
  78. // to ignore runtime.js
  79. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  80. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  81. include: 'initial',
  82. },
  83. ])
  84. // when there are many pages, it will cause too many meaningless requests
  85. config.plugins.delete('prefetch')
  86. // set svg-sprite-loader
  87. config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
  88. config.module
  89. .rule('icons')
  90. .test(/\.svg$/)
  91. .include.add(resolve('src/assets/icons'))
  92. .end()
  93. .use('svg-sprite-loader')
  94. .loader('svg-sprite-loader')
  95. .options({
  96. symbolId: 'icon-[name]',
  97. })
  98. .end()
  99. // set preserveWhitespace
  100. config.module
  101. .rule('vue')
  102. .use('vue-loader')
  103. .loader('vue-loader')
  104. .tap((options) => {
  105. options.compilerOptions.preserveWhitespace = true
  106. return options
  107. })
  108. .end()
  109. config.when(process.env.NODE_ENV !== 'development', (config) => {
  110. config
  111. .plugin('ScriptExtHtmlWebpackPlugin')
  112. .after('html')
  113. .use('script-ext-html-webpack-plugin', [
  114. {
  115. // `runtime` must same as runtimeChunk name. default is `runtime`
  116. inline: /runtime\..*\.js$/,
  117. },
  118. ])
  119. .end()
  120. config.optimization.splitChunks({
  121. chunks: 'all',
  122. cacheGroups: {
  123. libs: {
  124. name: 'chunk-libs',
  125. test: /[\\/]node_modules[\\/]/,
  126. priority: 10,
  127. chunks: 'initial', // only package third parties that are initially dependent
  128. },
  129. elementUI: {
  130. name: 'chunk-elementUI', // split elementUI into a single package
  131. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  132. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  133. },
  134. commons: {
  135. name: 'chunk-commons',
  136. test: resolve('src/components'), // can customize your rules
  137. minChunks: 3, // minimum common number
  138. priority: 5,
  139. reuseExistingChunk: true,
  140. },
  141. },
  142. })
  143. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  144. config.optimization.runtimeChunk('single')
  145. // 删除设置文件夹,防止覆盖
  146. config.plugin('CleanWebpackPlugin').use(CleanWebpackPlugin, [
  147. {
  148. cleanAfterEveryBuildPatterns: ['static/setting*'],
  149. },
  150. ])
  151. })
  152. },
  153. transpileDependencies: [/\/node_modules\/vue-echarts\//, /\/node_modules\/resize-detector\//],
  154. }