沈阳玫苑物业管理前端
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.

139 lines
4.2 KiB

4 years ago
4 years 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 || 'LE-IT' // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9090 // dev port
  14. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  15. const productionGzipExtensions = ['js', 'css']
  16. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  17. module.exports = {
  18. /**
  19. * You will need to set publicPath if you plan to deploy your site under a sub path,
  20. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  21. * then publicPath should be set to "/bar/".
  22. * In most cases please use '/' !!!
  23. * Detail: https://cli.vuejs.org/config/#publicpath
  24. */
  25. publicPath: '/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. lintOnSave: true,
  29. devServer: {
  30. port: port,
  31. overlay: {
  32. warnings: true,
  33. errors: true
  34. }
  35. },
  36. configureWebpack: {
  37. name: name,
  38. resolve: {
  39. alias: {
  40. '@': resolve('src')
  41. }
  42. },
  43. // 关闭webpack的性能提示
  44. performance: {
  45. hints: false,
  46. }
  47. },
  48. chainWebpack(config) {
  49. config.plugin('compression-webpack-plugin').use(
  50. new CompressionWebpackPlugin({
  51. filename: '[path][base].gz',
  52. algorithm: 'gzip',
  53. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), // 匹配文件名
  54. threshold: 10240, // 对10K以上的数据进行压缩
  55. minRatio: 0.8,
  56. deleteOriginalAssets: false // 是否删除源文件
  57. })
  58. )
  59. // set svg-sprite-loader
  60. config.module
  61. .rule('svg')
  62. .exclude.add(resolve('src/icons'))
  63. .end()
  64. config.module
  65. .rule('icons')
  66. .test(/\.svg$/)
  67. .include.add(resolve('src/icons'))
  68. .end()
  69. .use('svg-sprite-loader')
  70. .loader('svg-sprite-loader')
  71. .options({
  72. symbolId: 'icon-[name]'
  73. })
  74. .end()
  75. // set preserveWhitespace
  76. config.module
  77. .rule('vue')
  78. .use('vue-loader')
  79. .loader('vue-loader')
  80. .tap(options => {
  81. options.compilerOptions.preserveWhitespace = true
  82. return options
  83. })
  84. .end()
  85. config
  86. // https://webpack.js.org/configuration/devtool/#development
  87. .when(process.env.NODE_ENV === 'development',
  88. config => config.devtool('cheap-source-map')
  89. )
  90. config
  91. .when(process.env.NODE_ENV !== 'development',
  92. config => {
  93. config
  94. .plugin('ScriptExtHtmlWebpackPlugin')
  95. .after('html')
  96. .use('script-ext-html-webpack-plugin', [{
  97. // `runtime` must same as runtimeChunk name. default is `runtime`
  98. inline: /runtime\..*\.js$/
  99. }])
  100. .end()
  101. config
  102. .optimization.splitChunks({
  103. chunks: 'all',
  104. cacheGroups: {
  105. libs: {
  106. name: 'chunk-libs',
  107. test: /[\\/]node_modules[\\/]/,
  108. priority: 10,
  109. chunks: 'initial' // only package third parties that are initially dependent
  110. },
  111. elementUI: {
  112. name: 'chunk-elementUI', // split elementUI into a single package
  113. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  114. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  115. },
  116. commons: {
  117. name: 'chunk-commons',
  118. test: resolve('src/components'), // can customize your rules
  119. minChunks: 3, // minimum common number
  120. priority: 5,
  121. reuseExistingChunk: true
  122. }
  123. }
  124. })
  125. config.optimization.runtimeChunk('single')
  126. }
  127. )
  128. },
  129. productionSourceMap: false
  130. }