- 提取
.env.development.env.dev-prod.env.production.env.test等配置- 将
base_apibase_urldist_url放到配置文件 - 修改
scripts中的命令
- 将
jenkins流水线持续集成- cdn加速
- 剔除
console/debugger - 全局样式引用
- 合理使用
mixin - 模块化
vuexrouter - 预加载
prefetch - 路由懒加载
- 配置文件夹别名
- 去除map文件
productinSourceMap: process.env.NODE_ENV !== "production",
- 分离css
优化less/sass
css: {sourceMap: process.env.NODE_ENV === 'development',requireModuleExtension: true,loaderOptions: {css: {modules: {getLocalIdent: (context, localIdentName, localName, options) => {let i = 0while(i < cssModuleExcludes.length) {if (cssModuleExcludes[i].test(localName)) return localNamei += 1}let filePath = context.context.replace(context.rootContext, '')let filename = context.resourcePath.replace(context.context, '').replace(/^\/|\\|\.vue$/g, '')filePath = upath.normalize(filePath)filePath = filePath.replace(/\/src\/components\//, '/c/')filePath = filePath.replace(/\/src\/views\//, '/v/')filePath = filePath.split(/\/|\\/).filter(i => i.length).join('-')if (filename === 'index') return `${filePath}__${localName}`return `${filePath}-${filename}__${localName}`},},},// pass options to less-loaderless: {lessOptions: {modifyVars: {'primary-color': '#3977EB','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"',},javascriptEnabled: true},},}},
图片压缩
lodash优化打包结果分析
chainWebpack(config) {config.plugin("lodashReplace").use(new LodashModuleReplacementPlugin());//优化lodash// 移除 prefetch 插件config.plugins.delete('prefetch')// 移除 preload 插件config.plugins.delete('preload')const entry = config.entry('app')entry.add('babel-polyfill')// 关闭打包大小限制config.performance.set('hints', false)// 进行打包情况的监测if (process.env.analyzer) {config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)}config.plugin('ignore-moment').use(new webpack.IgnorePlugin(/^\.\/locale$/,// /^\.\/locale\/zh-cn$/,/moment$/))//忽略/moment/locale下的所有文件// set svg-sprite-loaderconfig.module.rule('svg').exclude.add(resolve('src/icons')).end()config.module.rule('icons').test(/\.svg$/).include.add(resolve('src/icons')).end().use('svg-sprite-loader').loader('svg-sprite-loader').options({symbolId: 'icon-[name]'}).end()},
公共代码抽离
开启
gzipconfigureWebpack: config => {const conf = {output: {sourcePrefix: ' '},amd: {toUrlUndefined: true},resolve: {alias: {'vue$': 'vue/dist/vue.esm.js','@': path.resolve('src'),}},plugins: [],}// 添加gzip压缩if (process.env.NODE_ENV === 'production') {conf.plugins.push(new CompressionPlugin({test: /\.js$|\.html$|\.css$/, // 匹配文件名threshold: 10240, // 对超过 10K 的数据进行压缩deleteOriginalAssets: false,}))}return conf}
