vue.config.js 5.0 KB

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