vue.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. const path = require('path')
  2. const defaultSettings = require('./src/settings.js')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const name = defaultSettings.title || 'vue Admin Template' // page title
  7. // If your port is set to 80,
  8. // use administrator privileges to execute the command line.
  9. // For example, Mac: sudo npm run
  10. // You can change the port by the following methods:
  11. // port = 9528 npm run dev OR npm run dev --port = 9528
  12. const port = process.env.port || process.env.npm_config_port || 9529 // dev port
  13. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  14. module.exports = {
  15. /**
  16. * You will need to set publicPath if you plan to deploy your site under a sub path,
  17. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  18. * then publicPath should be set to "/bar/".
  19. * In most cases please use '/' !!!
  20. * Detail: https://cli.vuejs.org/config/#publicpath
  21. */
  22. runtimeCompiler: true,
  23. publicPath: './',
  24. outputDir: 'dist',
  25. assetsDir: 'static',
  26. // lintOnSave: process.env.NODE_ENV === 'development',
  27. lintOnSave: false,
  28. productionSourceMap: false,
  29. devServer: {
  30. port,
  31. open: true,
  32. overlay: {
  33. warnings: false,
  34. errors: false
  35. },
  36. proxy: {
  37. '/businessapi': {
  38. // target: 'http://192.168.0.91:9104',
  39. target: 'https://nsbusinessapitest.tuanfengkeji.cn',
  40. // target: 'https://nsbusinessapi.tuanfengkeji.cn',
  41. changeOrigin: true,
  42. pathRewrite: {
  43. '^/businessapi': ''
  44. }
  45. },
  46. '/canvasApi': {
  47. // target: 'http://192.168.0.91:9104', // 测试
  48. target: 'https://nsbusinessapitest.tuanfengkeji.cn',
  49. // target: 'https://nsbusinessapi.tuanfengkeji.cn',
  50. changeOrigin: true,
  51. pathRewrite: {
  52. '^/canvasApi': ''
  53. }
  54. }
  55. }
  56. },
  57. configureWebpack: {
  58. // provide the app's title in webpack's name field, so that
  59. // it can be accessed in index.html to inject the correct title.
  60. name,
  61. resolve: {
  62. alias: {
  63. '@': resolve('src'),
  64. '@@': resolve('canvas-container')
  65. }
  66. }
  67. },
  68. // 配置全局样式变量
  69. css: {
  70. loaderOptions: {
  71. sass: {
  72. prependData: `@import "canvas-container/styles/index.scss";`
  73. }
  74. }
  75. },
  76. // 配置多页面入口
  77. pages: {
  78. index: {
  79. entry: 'src/main.js',
  80. template: 'public/index.html',
  81. filename: 'index.html',
  82. chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'index']
  83. },
  84. canvas: {
  85. entry: 'canvas-container/main.js',
  86. template: 'public/canvas.html',
  87. filename: 'canvas.html',
  88. chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'canvas']
  89. }
  90. },
  91. chainWebpack(config) {
  92. // it can improve the speed of the first screen, it is recommended to turn on preload
  93. // config.plugin('preload').tap(() => [
  94. // {
  95. // rel: 'preload',
  96. // // to ignore runtime.js
  97. // // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  98. // fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  99. // include: 'initial'
  100. // }
  101. // ])
  102. // when there are many pages, it will cause too many meaningless requests
  103. config.plugins.delete('prefetch')
  104. // set svg-sprite-loader
  105. config.module
  106. .rule('svg')
  107. .exclude.add(resolve('src/icons'))
  108. .end()
  109. config.module
  110. .rule('icons')
  111. .test(/\.svg$/)
  112. .include.add(resolve('src/icons'))
  113. .end()
  114. .use('svg-sprite-loader')
  115. .loader('svg-sprite-loader')
  116. .options({
  117. symbolId: 'icon-[name]'
  118. })
  119. .end()
  120. config
  121. .when(
  122. process.env.NODE_ENV !== 'development',
  123. (config) => {
  124. config
  125. .plugin('ScriptExtHtmlWebpackPlugin')
  126. .after('html')
  127. .use('script-ext-html-webpack-plugin', [ {
  128. // `runtime` must same as runtimeChunk name. default is `runtime`
  129. inline: /runtime\..*\.js$/
  130. } ])
  131. .end()
  132. config
  133. .optimization.splitChunks({
  134. chunks: 'all',
  135. cacheGroups: {
  136. libs: {
  137. name: 'chunk-libs',
  138. test: /[\\/]node_modules[\\/]/,
  139. priority: 10,
  140. chunks: 'initial' // only package third parties that are initially dependent
  141. },
  142. elementUI: {
  143. name: 'chunk-elementUI', // split elementUI into a single package
  144. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  145. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  146. },
  147. commons: {
  148. name: 'chunk-commons',
  149. test: resolve('src/components'), // can customize your rules
  150. minChunks: 3, // minimum common number
  151. priority: 5,
  152. reuseExistingChunk: true
  153. }
  154. }
  155. })
  156. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  157. config.optimization.runtimeChunk('single')
  158. }
  159. )
  160. }
  161. }