vue.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. changeOrigin: true,
  50. pathRewrite: {
  51. '^/canvasApi': ''
  52. }
  53. }
  54. }
  55. },
  56. configureWebpack: {
  57. // provide the app's title in webpack's name field, so that
  58. // it can be accessed in index.html to inject the correct title.
  59. name,
  60. resolve: {
  61. alias: {
  62. '@': resolve('src'),
  63. '@@': resolve('canvas-container')
  64. }
  65. }
  66. },
  67. // 配置全局样式变量
  68. css: {
  69. loaderOptions: {
  70. sass: {
  71. prependData: `@import "canvas-container/styles/index.scss";`
  72. }
  73. }
  74. },
  75. // 配置多页面入口
  76. pages: {
  77. index: {
  78. entry: 'src/main.js',
  79. template: 'public/index.html',
  80. filename: 'index.html',
  81. chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'index']
  82. },
  83. canvas: {
  84. entry: 'canvas-container/main.js',
  85. template: 'public/canvas.html',
  86. filename: 'canvas.html',
  87. chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'canvas']
  88. }
  89. },
  90. chainWebpack(config) {
  91. // it can improve the speed of the first screen, it is recommended to turn on preload
  92. // config.plugin('preload').tap(() => [
  93. // {
  94. // rel: 'preload',
  95. // // to ignore runtime.js
  96. // // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  97. // fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  98. // include: 'initial'
  99. // }
  100. // ])
  101. // when there are many pages, it will cause too many meaningless requests
  102. config.plugins.delete('prefetch')
  103. // set svg-sprite-loader
  104. config.module
  105. .rule('svg')
  106. .exclude.add(resolve('src/icons'))
  107. .end()
  108. config.module
  109. .rule('icons')
  110. .test(/\.svg$/)
  111. .include.add(resolve('src/icons'))
  112. .end()
  113. .use('svg-sprite-loader')
  114. .loader('svg-sprite-loader')
  115. .options({
  116. symbolId: 'icon-[name]'
  117. })
  118. .end()
  119. config
  120. .when(
  121. process.env.NODE_ENV !== 'development',
  122. (config) => {
  123. config
  124. .plugin('ScriptExtHtmlWebpackPlugin')
  125. .after('html')
  126. .use('script-ext-html-webpack-plugin', [ {
  127. // `runtime` must same as runtimeChunk name. default is `runtime`
  128. inline: /runtime\..*\.js$/
  129. } ])
  130. .end()
  131. config
  132. .optimization.splitChunks({
  133. chunks: 'all',
  134. cacheGroups: {
  135. libs: {
  136. name: 'chunk-libs',
  137. test: /[\\/]node_modules[\\/]/,
  138. priority: 10,
  139. chunks: 'initial' // only package third parties that are initially dependent
  140. },
  141. elementUI: {
  142. name: 'chunk-elementUI', // split elementUI into a single package
  143. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  144. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  145. },
  146. commons: {
  147. name: 'chunk-commons',
  148. test: resolve('src/components'), // can customize your rules
  149. minChunks: 3, // minimum common number
  150. priority: 5,
  151. reuseExistingChunk: true
  152. }
  153. }
  154. })
  155. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  156. config.optimization.runtimeChunk('single')
  157. }
  158. )
  159. }
  160. }