vue.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const path = require('path')
  2. function resolve(dir) {
  3. return path.join(__dirname, dir)
  4. }
  5. module.exports = {
  6. publicPath: './',
  7. outputDir: 'dist',
  8. assetsDir: 'static',
  9. productionSourceMap: false,
  10. filenameHashing: false,
  11. lintOnSave: false,
  12. css: {
  13. requireModuleExtension: true
  14. },
  15. devServer: {
  16. port: 8888, // 端口
  17. open: true, // 启动后打开浏览器
  18. },
  19. chainWebpack: config => {
  20. //最小化代码
  21. config.optimization.minimize(true)
  22. //分割代码
  23. config.optimization.splitChunks({
  24. chunks: 'all'
  25. })
  26. // //压缩图片
  27. config.module
  28. .rule('images')
  29. .use('image-webpack-loader')
  30. .loader('image-webpack-loader')
  31. .options({
  32. bypassOnDebug: true
  33. })
  34. .end()
  35. //set svg-sprite-loader
  36. config.module.rule('svg').exclude.add(resolve('src/icon')).end()
  37. config.module
  38. .rule('icons')
  39. .test(/\.svg$/)
  40. .include.add(resolve('src/icon'))
  41. .end()
  42. .use('svg-sprite-loader')
  43. .loader('svg-sprite-loader')
  44. .options({
  45. symbolId: 'icon-[name]'
  46. })
  47. .end()
  48. },
  49. configureWebpack: config => {
  50. // 打包文件大小配置
  51. config.performance = {
  52. maxEntrypointSize: 10000000,
  53. maxAssetSize: 30000000
  54. }
  55. }
  56. }