VUEvue

vue-cli项目打包上线前的优化

2019-06-06  本文已影响96人  小虾米前端

一。引入 CDN
// 不会发生变动的js库可以放入script标签中,从外部引入
// 注意一点:格式为 'aaa' : 'bbb', 其中,aaa表示要引入的资源的名字,bbb表示该模块提供给外部引用的名字,由对应的库自定。例如,vue为Vue,vue-router为VueRouter.

webpack.base.conf.js文件
  externals: {
    'vue':'Vue',
    'html2canvas': 'html2canvas',
    'vue-router': 'VueRouter',
    'vuex': 'Vuex',
    'crypto-js': 'CryptoJS',
    'jsencrypt': 'JSEncrypt'
  },

index.html文件
    <script src="https://cdn.staticfile.org/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
    <script src="https://cdn.staticfile.org/vue-router/3.0.1/vue-router.min.js"></script>
    <script src="https://cdn.staticfile.org/vuex/3.0.1/vuex.min.js"></script>
    <script src="https://cdn.staticfile.org/crypto-js/3.1.9-1/crypto-js.min.js"></script>
    <script src="https://cdn.staticfile.org/jsencrypt/3.0.0-rc.1/jsencrypt.min.js"></script>
    <script src="https://cdn.staticfile.org/vue/2.6.10/vue.min.js"></script>

二。去除 .map文件
 在项目 根目录 config/index.js 中 build 内找到 productionSourceMap: true, 把 true改为****false。从而重新打包以后,系统就不会自动生成 map文件了。

image

三。使用Gzip压缩
1.服务器那边得开启gzip

image.png
2.根目录config/index.js 中 build 内找到 **productionGzip: false, **把 **false****改为****true。 image

3.安装插件 compression-webpack-plugin  注:安装的时候带上版本号,现在 compression-webpack-plugin 2.0已出,默认该命令安装最新版,最新版本和当前的webpack不匹配,要报错。

cnpm install --save-dev compression-webpack-plugin@1.1.12

上一篇下一篇

猜你喜欢

热点阅读