zoukankan      html  css  js  c++  java
  • 使用vue打包,vendor文件过大,或者是app.js文件很大

    我的解决办法:

    1、把不常改变的库放到index.html中,通过cdn引入,比如下面这样:

    然后找到build/webpack.base.conf.js文件,在 module.exports = { } 中添加以下代码

    externals: {
        'vue': 'Vue',
        'vue-router': 'VueRouter',
        'element-ui': 'ELEMENT',
     },

    这样webpack就不会把vue.js, vue-router, element-ui库打包了。声明一下,我把main.js中对element的引入删掉了,不然我发现打包后的app.css还是会把element的css打包进去,删掉后就没了。

    然后你打包就会发现vendor文件小了很多~

    在项目config/index.js中可以开启gzip压缩,对打包优化也有很大的帮助

          1.首先安装插件 compression-webpack-plugin

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

          2.设置productionGzip: true

    webpackConfig.plugins.push(
    new CompressionWebpackPlugin({
    asset: '[path].gz[query]',
    algorithm: 'gzip',
    test: new RegExp(
    '\.(' +
    config.build.productionGzipExtensions.join('|') +
    ')$'
    ),
    threshold: 10240,
    // deleteOriginalAssets:true, //删除源文件,不建议
    minRatio: 0.8
    })
    )

    修改服务器的配置,这里的服务器是Nginx 
    找到conf目录下的nginx.conf ,开启gzip,并设置gzip的类型,如下

    gzip on; 

          gzip_buffers 4 16k;

          gzip_comp_level 5;

          gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

  • 相关阅读:
    npm配置国内源方法
    数据库—事务—隔离级别
    Mybatis—日志
    Mybatis—动态 SQL
    Mybatis—mapper.xml配置文件
    declare命令
    shell杂项
    流程控制语句
    第一篇博客
    Linux 命令[2]:mkdir
  • 原文地址:https://www.cnblogs.com/web-chuanfa/p/11162194.html
Copyright © 2011-2022 走看看