• 提取 .env.development .env.dev-prod .env.production .env.test 等配置
      • base_api base_url dist_url 放到配置文件
      • 修改 scripts 中的命令
    • jenkins 流水线持续集成
    • cdn加速
    • 剔除 console/debugger
    • 全局样式引用
    • 合理使用 mixin
    • 模块化 vuex router
    • 预加载 prefetch
    • 路由懒加载
    • 配置文件夹别名
    • 去除map文件
      • productinSourceMap: process.env.NODE_ENV !== "production",
    • 分离css
    • 优化less/sass

      1. css: {
      2. sourceMap: process.env.NODE_ENV === 'development',
      3. requireModuleExtension: true,
      4. loaderOptions: {
      5. css: {
      6. modules: {
      7. getLocalIdent: (context, localIdentName, localName, options) => {
      8. let i = 0
      9. while(i < cssModuleExcludes.length) {
      10. if (cssModuleExcludes[i].test(localName)) return localName
      11. i += 1
      12. }
      13. let filePath = context.context.replace(context.rootContext, '')
      14. let filename = context.resourcePath.replace(context.context, '').replace(/^\/|\\|\.vue$/g, '')
      15. filePath = upath.normalize(filePath)
      16. filePath = filePath.replace(/\/src\/components\//, '/c/')
      17. filePath = filePath.replace(/\/src\/views\//, '/v/')
      18. filePath = filePath.split(/\/|\\/).filter(i => i.length).join('-')
      19. if (filename === 'index') return `${filePath}__${localName}`
      20. return `${filePath}-${filename}__${localName}`
      21. },
      22. },
      23. },
      24. // pass options to less-loader
      25. less: {
      26. lessOptions: {
      27. modifyVars: {
      28. 'primary-color': '#3977EB',
      29. 'font-family': ' "Microsoft YaHei","Chinese Quote","PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans GB", "Helvetica Neue", Helvetica, Arial, sans-serif,"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
      30. },
      31. javascriptEnabled: true
      32. },
      33. },
      34. }
      35. },
    • 图片压缩

    • lodash 优化
    • 打包结果分析

      1. chainWebpack(config) {
      2. config.plugin("lodashReplace")
      3. .use(new LodashModuleReplacementPlugin());//优化lodash
      4. // 移除 prefetch 插件
      5. config.plugins.delete('prefetch')
      6. // 移除 preload 插件
      7. config.plugins.delete('preload')
      8. const entry = config.entry('app')
      9. entry.add('babel-polyfill')
      10. // 关闭打包大小限制
      11. config.performance.set('hints', false)
      12. // 进行打包情况的监测
      13. if (process.env.analyzer) {
      14. config
      15. .plugin('webpack-bundle-analyzer')
      16. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
      17. }
      18. config
      19. .plugin('ignore-moment')
      20. .use(new webpack.IgnorePlugin(
      21. /^\.\/locale$/,
      22. // /^\.\/locale\/zh-cn$/,
      23. /moment$/
      24. ))//忽略/moment/locale下的所有文件
      25. // set svg-sprite-loader
      26. config.module
      27. .rule('svg')
      28. .exclude.add(resolve('src/icons'))
      29. .end()
      30. config.module
      31. .rule('icons')
      32. .test(/\.svg$/)
      33. .include.add(resolve('src/icons'))
      34. .end()
      35. .use('svg-sprite-loader')
      36. .loader('svg-sprite-loader')
      37. .options({
      38. symbolId: 'icon-[name]'
      39. })
      40. .end()
      41. },
    • 公共代码抽离

    • 开启 gzip

      1. configureWebpack: config => {
      2. const conf = {
      3. output: {
      4. sourcePrefix: ' '
      5. },
      6. amd: {
      7. toUrlUndefined: true
      8. },
      9. resolve: {
      10. alias: {
      11. 'vue$': 'vue/dist/vue.esm.js',
      12. '@': path.resolve('src'),
      13. }
      14. },
      15. plugins: [],
      16. }
      17. // 添加gzip压缩
      18. if (process.env.NODE_ENV === 'production') {
      19. conf.plugins.push(new CompressionPlugin({
      20. test: /\.js$|\.html$|\.css$/, // 匹配文件名
      21. threshold: 10240, // 对超过 10K 的数据进行压缩
      22. deleteOriginalAssets: false,
      23. }))
      24. }
      25. return conf
      26. }