GAAS GFrame项目web前端
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.

136 lines
4.1 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. version: resolve('static/js/version.log.js')
  42. }
  43. }
  44. },
  45. chainWebpack(config) {
  46. config.plugin('compression-webpack-plugin').use(
  47. new CompressionWebpackPlugin({
  48. filename: '[path][base].gz',
  49. algorithm: 'gzip',
  50. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), // 匹配文件名
  51. threshold: 10240, // 对10K以上的数据进行压缩
  52. minRatio: 0.8,
  53. deleteOriginalAssets: false // 是否删除源文件
  54. })
  55. )
  56. // set svg-sprite-loader
  57. config.module
  58. .rule('svg')
  59. .exclude.add(resolve('src/icons'))
  60. .end()
  61. config.module
  62. .rule('icons')
  63. .test(/\.svg$/)
  64. .include.add(resolve('src/icons'))
  65. .end()
  66. .use('svg-sprite-loader')
  67. .loader('svg-sprite-loader')
  68. .options({
  69. symbolId: 'icon-[name]'
  70. })
  71. .end()
  72. // set preserveWhitespace
  73. config.module
  74. .rule('vue')
  75. .use('vue-loader')
  76. .loader('vue-loader')
  77. .tap(options => {
  78. options.compilerOptions.preserveWhitespace = true
  79. return options
  80. })
  81. .end()
  82. config
  83. // https://webpack.js.org/configuration/devtool/#development
  84. .when(process.env.NODE_ENV === 'development',
  85. config => config.devtool('cheap-source-map')
  86. )
  87. config
  88. .when(process.env.NODE_ENV !== 'development',
  89. config => {
  90. config
  91. .plugin('ScriptExtHtmlWebpackPlugin')
  92. .after('html')
  93. .use('script-ext-html-webpack-plugin', [{
  94. // `runtime` must same as runtimeChunk name. default is `runtime`
  95. inline: /runtime\..*\.js$/
  96. }])
  97. .end()
  98. config
  99. .optimization.splitChunks({
  100. chunks: 'all',
  101. cacheGroups: {
  102. libs: {
  103. name: 'chunk-libs',
  104. test: /[\\/]node_modules[\\/]/,
  105. priority: 10,
  106. chunks: 'initial' // only package third parties that are initially dependent
  107. },
  108. elementUI: {
  109. name: 'chunk-elementUI', // split elementUI into a single package
  110. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  111. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  112. },
  113. commons: {
  114. name: 'chunk-commons',
  115. test: resolve('src/components'), // can customize your rules
  116. minChunks: 3, // minimum common number
  117. priority: 5,
  118. reuseExistingChunk: true
  119. }
  120. }
  121. })
  122. config.optimization.runtimeChunk('single')
  123. }
  124. )
  125. },
  126. productionSourceMap: false
  127. }