vue.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) { return path.join(__dirname, dir) }
  5. const name = defaultSettings.title || 'PAGE TITLE' // page title
  6. const port = process.env.port || process.env.npm_config_port || 8080 // dev port
  7. module.exports = {
  8. publicPath: './',
  9. outputDir: 'dist',
  10. assetsDir: 'static',
  11. lintOnSave: false,
  12. productionSourceMap: false,
  13. devServer: {
  14. port: port,
  15. open: true,
  16. allowedHosts: 'all'
  17. },
  18. configureWebpack: {
  19. name: name,
  20. resolve: {
  21. alias: {
  22. '@': resolve('src')
  23. }
  24. }
  25. },
  26. chainWebpack(config) {
  27. config.plugins.delete('prefetch')
  28. config.module
  29. .rule('svg')
  30. .exclude.add(resolve('src/icons'))
  31. .end()
  32. config.module
  33. .rule('icons')
  34. .test(/\.svg$/)
  35. .include.add(resolve('src/icons'))
  36. .end()
  37. .use('svg-sprite-loader')
  38. .loader('svg-sprite-loader')
  39. .options({
  40. symbolId: 'icon-[name]'
  41. })
  42. .end()
  43. config
  44. .when(process.env.NODE_ENV !== 'development',
  45. config => {
  46. config
  47. .plugin('ScriptExtHtmlWebpackPlugin')
  48. .after('html')
  49. .use('script-ext-html-webpack-plugin', [{
  50. // `runtime` must same as runtimeChunk name. default is `runtime`
  51. inline: /runtime\..*\.js$/
  52. }])
  53. .end()
  54. config
  55. .optimization.splitChunks({
  56. chunks: 'all',
  57. cacheGroups: {
  58. libs: {
  59. name: 'chunk-libs',
  60. test: /[\\/]node_modules[\\/]/,
  61. priority: 10,
  62. chunks: 'initial' // only package third parties that are initially dependent
  63. },
  64. elementUI: {
  65. name: 'chunk-elementUI', // split elementUI into a single package
  66. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  67. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  68. },
  69. commons: {
  70. name: 'chunk-commons',
  71. test: resolve('src/accident'), // can customize your rules
  72. minChunks: 3, // minimum common number
  73. priority: 5,
  74. reuseExistingChunk: true
  75. }
  76. }
  77. })
  78. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  79. config.optimization.runtimeChunk('single')
  80. }
  81. )
  82. config.externals({ './cptable': 'var cptable' })
  83. }
  84. }