vue.config.js 5.6 KB

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