交通管理局公文项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.6 KiB

2 months ago
  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 // 网址标题
  8. const port = 8016 // 端口配置
  9. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  10. // const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
  11. // const createServerConfig = compilation => {
  12. // const serverConfig = {
  13. // BASE_URL: '' // 打包后生成的文件内容,接口地址
  14. // }
  15. // return JSON.stringify(serverConfig)
  16. // }
  17. module.exports = {
  18. // hash 模式下可使用
  19. publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
  20. // publicPath: '/',
  21. outputDir: 'dist',
  22. assetsDir: 'static',
  23. lintOnSave: process.env.NODE_ENV === 'development',
  24. productionSourceMap: false,
  25. devServer: {
  26. port: port,
  27. open: true,
  28. overlay: {
  29. warnings: false,
  30. errors: true
  31. },
  32. proxy: {
  33. '/api': {
  34. target: process.env.VUE_APP_BASE_API,
  35. changeOrigin: true,
  36. pathRewrite: {
  37. '^/api': 'api'
  38. }
  39. },
  40. '/auth': {
  41. target: process.env.VUE_APP_BASE_API,
  42. changeOrigin: true,
  43. pathRewrite: {
  44. '^/auth': 'auth'
  45. }
  46. },
  47. '/ureport': {
  48. target: process.env.VUE_APP_BASE_API,
  49. ws: false,
  50. changeOrigin: true,
  51. pathRewrite: {
  52. '^/ureport': '/ureport'
  53. }
  54. }
  55. }
  56. },
  57. configureWebpack: {
  58. name: name,
  59. resolve: {
  60. alias: {
  61. '@': resolve('src'),
  62. '@crud': resolve('src/components/Crud')
  63. }
  64. },
  65. performance: {
  66. hints: 'warning',
  67. // 入口起点的最大体积
  68. maxEntrypointSize: 50000000,
  69. // 生成文件的最大体积
  70. maxAssetSize: 30000000
  71. }
  72. // plugins: [
  73. // new GenerateAssetPlugin({
  74. // filename: 'server-config.json',
  75. // fn: (compilation, cb) => {
  76. // cb(null, createServerConfig(compilation))
  77. // },
  78. // extraFiles: []
  79. // })
  80. // ]
  81. },
  82. chainWebpack(config) {
  83. config.plugins.delete('preload') // TODO: need test
  84. config.plugins.delete('prefetch') // TODO: need test
  85. // set svg-sprite-loader
  86. config.module
  87. .rule('svg')
  88. .exclude.add(resolve('src/assets/icons'))
  89. .end()
  90. config.module
  91. .rule('icons')
  92. .test(/\.svg$/)
  93. .include.add(resolve('src/assets/icons'))
  94. .end()
  95. .use('svg-sprite-loader')
  96. .loader('svg-sprite-loader')
  97. .options({
  98. symbolId: 'icon-[name]'
  99. })
  100. .end()
  101. // set preserveWhitespace
  102. config.module
  103. .rule('vue')
  104. .use('vue-loader')
  105. .loader('vue-loader')
  106. .tap(options => {
  107. options.compilerOptions.preserveWhitespace = true
  108. return options
  109. })
  110. .end()
  111. config
  112. // https://webpack.js.org/configuration/devtool/#development
  113. .when(process.env.NODE_ENV === 'development',
  114. config => config.devtool('cheap-source-map')
  115. )
  116. config
  117. .when(process.env.NODE_ENV !== 'development',
  118. config => {
  119. config
  120. .plugin('ScriptExtHtmlWebpackPlugin')
  121. .after('html')
  122. .use('script-ext-html-webpack-plugin', [{
  123. // `runtime` must same as runtimeChunk name. default is `runtime`
  124. inline: /runtime\..*\.js$/
  125. }])
  126. .end()
  127. config
  128. .optimization.splitChunks({
  129. chunks: 'all',
  130. cacheGroups: {
  131. libs: {
  132. name: 'chunk-libs',
  133. test: /[\\/]node_modules[\\/]/,
  134. priority: 10,
  135. chunks: 'initial' // only package third parties that are initially dependent
  136. },
  137. elementUI: {
  138. name: 'chunk-elementUI', // split elementUI into a single package
  139. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  140. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  141. },
  142. commons: {
  143. name: 'chunk-commons',
  144. test: resolve('src/components'), // can customize your rules
  145. minChunks: 3, // minimum common number
  146. priority: 5,
  147. reuseExistingChunk: true
  148. }
  149. }
  150. })
  151. config.optimization.runtimeChunk('single')
  152. }
  153. )
  154. config.module
  155. .rule('mjs')
  156. .test(/\.mjs$/)
  157. .include
  158. .add(/node_modules/)
  159. .end()
  160. .type('javascript/auto')
  161. // 定义一个新的webpack模块规则,命名为md
  162. config.module.rule('md')
  163. // 通过.test()方法,指定这个规则应该匹配哪些文件
  164. // 这个规则将应用于所有以.md结尾的文件,即Markdown文件
  165. .test(/\.md/)
  166. // 使用vue-loader来处理Markdown文件
  167. .use('vue-loader')
  168. .loader('vue-loader')
  169. .end()
  170. // 指定vue-markdown-loader来处理Markdown文件
  171. .use('vue-markdown-loader')
  172. // 使用vue-markdown-loader包中的markdown-compiler模块来处理Markdown文件
  173. .loader('vue-markdown-loader/lib/markdown-compiler')
  174. // raw: true以原始字符串的形式处理Markdown内容,不进行HTML转义等处理。
  175. .options({
  176. raw: true
  177. })
  178. },
  179. transpileDependencies: [
  180. 'vue-echarts',
  181. 'resize-detector'
  182. ]
  183. }