美文网首页
Laravel框架优化vue前段文件打包 定位大文件

Laravel框架优化vue前段文件打包 定位大文件

作者: 路过的人儿 | 来源:发表于2018-10-19 15:26 被阅读0次

定位前端打包体积过大的原因 使用 webpack-bundle-analyzer

 执行`npm install --save-dev webpack-bundle-analyzer`

修改webpack.mix.js,注意Laravel自带的 webpack-mix 的配置方式与平常的webpack配置略有不同

let mix = require('laravel-mix');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.webpackConfig({
  plugins: [
    new BundleAnalyzerPlugin(),
  ],
}).js('resources/assets/js/app.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css')
    .extract(['vue','axios']);

可在packge.json 中添加

"analyz": "cross-env NODE_ENV=production npm_config_report=true npm run production"

执行按需引入

npm install babel-plugin-component -save-dev
npm install babel-preset-es2015
npm install babel-preset-vue
npm install babel --save-dev

在laravel根目录下创建.babelrc文件

{
  "presets": [
    ["es2015", { "modules": false }]
  ],
  "plugins": [["component", [
    {
      "libraryName": "element-ui",
      "styleLibraryName": "theme-chalk"
    }
  ]]]
}

按需引入element laravel

app.js 按如下修改


/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

// Vue.component('example', require('./components/Example.vue'));
// import Hello from './components/Hello.vue'; // 引入Hello 组件
import App from './App.vue';
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
import {
  Table, TableColumn, Row, Col,
  Input,
  Button
} from 'element-ui'

[
  Table, TableColumn, Row, Col,
  Input,
  Button
].forEach(Compo => Vue.use(Compo));

// Vue.use(ElementUI);

import router from './router/index.js';

const app = new Vue({
  el: '#app',
  router,
  render: h => h(App)
});

此时再去命令行进行打包 执行 npm run product / npm run dev / npm run analyz 进行打包

修改前


image.png

修改后


image.png

使用webpack-bundle-analyzer


image.png

相关文章

  • Laravel框架优化vue前段文件打包 定位大文件

    定位前端打包体积过大的原因 使用 webpack-bundle-analyzer 修改webpack.mix.js...

  • Vue打包大文件分析

    分析得知,占用空间的大文件如下: .map vendor.[hash].js app.[hash].css 其余的...

  • Vue 网站首页加载优化

    Vue 网站首页加载优化 本篇主要讲解 Vue项目打包后 vendor.js 文件很大 如何对它进行优化 以及开启...

  • 博客网站首页加载优化

    Vue 网站首页加载优化 本篇主要讲解 Vue项目打包后 vendor.js 文件很大 如何对它进行优化 以及开启...

  • vue-cli3打包优化

    打包的常用优化策略有: 1、去掉console.log 2、去掉sourcemap 3、库文件不参与打包 vue-...

  • Linux的nginx环境的vue 部署

    使用npm run build打包Vue项目(在此使用的是IVue-Admin框架),生成打包文件 查看nginx...

  • vue、react在webpack中代码分割,性能优化

    在使用vue-cli、create-react-app中,webpack构建的打包构建的单页应用会生成一个大文件。...

  • vue打包优化

    在初次vue打包之后,文件非常大,所以采取了几种方法优化打包,打包后文件大小确实是显著下降了,如果还有不完善的地方...

  • vue项目优化

    vue 项目优化 项目打包体积优化 通常vue项目通过webpack打包后,会出现vendor包的体积过大的情况,...

  • 2019-05-10

    vue 组件按需引用,vue-router懒加载,vue打包优化,加载动画 当打包构建应用时,Javascript...

网友评论

      本文标题:Laravel框架优化vue前段文件打包 定位大文件

      本文链接:https://www.haomeiwen.com/subject/qfoyzftx.html