Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update webpack-bundle-analyzer to ^4.1.0 #6091

Closed
genie-youn opened this issue Nov 28, 2020 · 5 comments · Fixed by #6092
Closed

update webpack-bundle-analyzer to ^4.1.0 #6091

genie-youn opened this issue Nov 28, 2020 · 5 comments · Fixed by #6092

Comments

@genie-youn
Copy link
Contributor

genie-youn commented Nov 28, 2020

What problem does this feature solve?

Hi teams 😄
Thanks for making awesome tool.

Into the subject..

webpack-bundle-analyzer 4.1.0 was released a few days ago: webpack-contrib/webpack-bundle-analyzer@v3.8.0...v4.1.0

In this update, the bfj module was replaced by a custom json writer, which resulted in many performance improvements.
(ref PR)

In my case, I use a large scale Vue Application in vue-cli, and when I changed the version, the performance was greatly improved as follows.

before

before

after

after

I've seen that there is no break change between versions, so what do you think of upgrading the version of webpack-bundle-analyzer to 4.1.0?

I prepared a pull request.

Thanks you 😄

What does the proposed API look like?

Update webpack-bundle-analyzer to ^4.1.0

@IndexXuan
Copy link
Contributor

@genie-youn Hi Bro,how to use smp(speed-measure-plugin) with vue-cli ?

@genie-youn
Copy link
Contributor Author

@IndexXuan
Hi, I tried these things.

1. in configureWebpack

vue.config.js

const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();

module.exports = {
  configureWebpack: smp.wrap({
    plugins: [
      new MyAwesomeWebpackPlugin()
    ]
  }),
  //...
}

2. in chainWebpack

You must delete preload plugin. speed-measure-webpack-plugin crash with PreloadPlugin. It seems bug in speed-measure-webpack-plugin

vue.config.js

\module.exports = {
  //...
  chainWebpack: config => {
    // *Must delete these plugins*
    config.plugins.delete('preload');
    config.plugins.delete('prefetch');
    // GraphQL Loader
    config.module
      .rule('graphql')
      .test(/\.graphql$/)
      .use('graphql-tag/loader')
        .loader('graphql-tag/loader')
        .end()
      // Add another loader
      .use('other-loader')
        .loader('other-loader')
        .end()

    config
      .plugin('html')
      .tap(args => {
          return [/* new args to pass to html-webpack-plugin's constructor */]
      })

    const wrappedConfig = smp.wrap(config.toConfig());
    config.toConfig = () => wrappedConfig;
  }
}

3. Modify vue-cli source in your project's node_modules

Some plugins that appended by vue-cli, (e.g. webpack-bundle-analyzer) speed-measure-webpack-plugin can't collect metric. becuase these plugins append after adopt speed-measure-webpack-plugin.

So to measure the speed of these plugins, we directly modify code of vue-cli.

Similarly, should delete preload plugin.

this point at node_modules/@vue/cli-service/libs/commands/build/index.js

if (args.clean) {
  await fs.remove(targetDir)
}

const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();

webpackConfig = smp.wrap(webpackConfig);

return new Promise((resolve, reject) => {
  webpack(webpackConfig, (err, stats) => {

It would be great if vue-cli support option. (like vue-cli-service build --measure-speed).
But the first thing to do is fix the speed-measure-webpack-plugin bug, so I'm looking at that part.

@IndexXuan
Copy link
Contributor

@genie-youn Thanks a lot. long time to find the solution.

so @sodatea , will smp be the built in function in Vue CLI, like https://umijs.org/zh-CN/docs/env-variables#speed_measure
e.g. SPEED_MEASURE=1 yarn build or yarn build --speed-measure

@ShuBuShao
Copy link

ShuBuShao commented Sep 29, 2021

module.exports = {
  chainWebpack: config => {
    config
      .plugin('speed-measure-webpack-plugin')
      .use(SpeedMeasurePlugin)
      .end()
  }
}

不用删除 preload plugin,
用上面的方式可以直接使用

@BuugMakerr
Copy link

module.exports = {
  chainWebpack: config => {
    config
      .plugin('speed-measure-webpack-plugin')
      .use(SpeedMeasurePlugin)
      .end()
  }
}

不用删除 preload plugin, 用上面的方式可以直接使用

但是这样好像不能测量插件的时间

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants