vue.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title // page title
  8. const port = 9527 // dev port
  9. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  10. module.exports = {
  11. // css: {
  12. // loaderOptions: {
  13. // less: {
  14. // lessOptions:{
  15. // modifyVars: {
  16. // hack: `true; @import "${path.resolve(__dirname, 'src/theme.less')}";`, //
  17. // }
  18. // }
  19. // }
  20. // }
  21. // },
  22. css: {
  23. loaderOptions: {
  24. less: {
  25. // 若 less-loader 版本小于 6.0,请移除 lessOptions 这一级,直接配置选项。
  26. lessOptions: {
  27. modifyVars: {
  28. // 此处修改样式
  29. "button-primary-border-color": '#1111'
  30. // 直接覆盖变量或者通过 less 文件覆盖
  31. },
  32. },
  33. },
  34. },
  35. },
  36. // css: {
  37. // loaderOptions: {
  38. // less: {
  39. // lessOptions: {
  40. // // 若 less-loader 版本小于 6.0,请移除 lessOptions 这一级,直接配置选项。
  41. // modifyVars: {
  42. // // 直接覆盖变量
  43. // 'green': '#111',
  44. // // 或者可以通过 less 文件覆盖(文件路径为绝对路径)
  45. // // hack: `true; @import "@/assets/theme.less')}";`
  46. // },
  47. // }
  48. // },
  49. // }
  50. // },
  51. /**
  52. * You will need to set publicPath if you plan to deploy your site under a sub path,
  53. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  54. * then publicPath should be set to "/bar/".
  55. * In most cases please use '/' !!!
  56. * Detail: https://cli.vuejs.org/config/#publicpath
  57. */
  58. publicPath: '/life',
  59. outputDir: 'life',
  60. assetsDir: 'static',
  61. // lintOnSave: process.env.NODE_ENV === 'development',
  62. productionSourceMap: false,
  63. devServer: {
  64. port: port,
  65. open: true,
  66. overlay: {
  67. warnings: false,
  68. errors: true
  69. },
  70. proxy: {
  71. // change xxx-api/login => mock/login
  72. // detail: https://cli.vuejs.org/config/#devserver-proxy
  73. [process.env.VUE_APP_BASE_API]: {
  74. target: `http://localhost:${port}/mock`,
  75. changeOrigin: true,
  76. pathRewrite: {
  77. ['^' + process.env.VUE_APP_BASE_API]: ''
  78. }
  79. }
  80. },
  81. // after: require('./mock/mock-server.js')
  82. },
  83. configureWebpack: {
  84. // provide the app's title in webpack's name field, so that
  85. // it can be accessed in index.html to inject the correct title.
  86. name: name,
  87. resolve: {
  88. alias: {
  89. '@': resolve('src')
  90. }
  91. }
  92. },
  93. lintOnSave: false,
  94. chainWebpack(config) {
  95. config.plugins.delete('preload') // TODO: need test
  96. config.plugins.delete('prefetch') // TODO: need test
  97. // set svg-sprite-loader
  98. config.module
  99. .rule('svg')
  100. .exclude.add(resolve('src/icons'))
  101. .end()
  102. config.module
  103. .rule('icons')
  104. .test(/\.svg$/)
  105. .include.add(resolve('src/icons'))
  106. .end()
  107. .use('svg-sprite-loader')
  108. .loader('svg-sprite-loader')
  109. .options({
  110. symbolId: 'icon-[name]'
  111. })
  112. .end()
  113. // set preserveWhitespace
  114. config.module
  115. .rule('vue')
  116. .use('vue-loader')
  117. .loader('vue-loader')
  118. .tap(options => {
  119. options.compilerOptions.preserveWhitespace = true
  120. return options
  121. })
  122. .end()
  123. config
  124. // https://webpack.js.org/configuration/devtool/#development
  125. .when(process.env.NODE_ENV === 'development',
  126. config => config.devtool('cheap-source-map')
  127. )
  128. config
  129. .when(process.env.NODE_ENV !== 'development',
  130. config => {
  131. config
  132. .plugin('ScriptExtHtmlWebpackPlugin')
  133. .after('html')
  134. .use('script-ext-html-webpack-plugin', [{
  135. // `runtime` must same as runtimeChunk name. default is `runtime`
  136. inline: /runtime\..*\.js$/
  137. }])
  138. .end()
  139. config
  140. .optimization.splitChunks({
  141. chunks: 'all',
  142. cacheGroups: {
  143. libs: {
  144. name: 'chunk-libs',
  145. test: /[\\/]node_modules[\\/]/,
  146. priority: 10,
  147. chunks: 'initial' // only package third parties that are initially dependent
  148. },
  149. commons: {
  150. name: 'chunk-commons',
  151. test: resolve('src/components'), // can customize your rules
  152. minChunks: 3, // minimum common number
  153. priority: 5,
  154. reuseExistingChunk: true
  155. }
  156. }
  157. })
  158. config.optimization.runtimeChunk('single')
  159. }
  160. )
  161. },
  162. }