speed-measure-webpack-plugin icon indicating copy to clipboard operation
speed-measure-webpack-plugin copied to clipboard

how about usage with multiple configs and a function with the env argument?

Open rosenfeld opened this issue 7 years ago • 10 comments

My webpack configuration returns a function receiving the "env" argument and returns multiple configurations. How am I supposed to integrate SMP with such a config?

Thanks in advance!

rosenfeld avatar Apr 02 '18 16:04 rosenfeld

Hey @rosenfeld

Just to clarify, do you mean a config like so?

module.exports = env => {
  return [conf1, conf2];
};

if so, then you can do the following:

module.exports = env => {
  return [conf1, conf2].map(smp.wrap);
};

however this isn't ideal... Ideally smp.wrap should just always work, no matter if you're wrapped a function, an array, or an object. I'll aim to get something like this added in v1.3

stephencookdev avatar Apr 02 '18 20:04 stephencookdev

That was my first attempt. I tried that, then I tried to smp.wrap([conf1, conf2]) and finally smp.wrap( env => {}). That first attempt, like you suggested, didn't seem to give me the right stats and only seemed to print the stats for the first config. Did you give it a try?

rosenfeld avatar Apr 02 '18 20:04 rosenfeld

I did, but with a stupid fake example - entirely possible I missed any issues with the second config not actually getting measured.

Sorry about that :/ I'll get a proper config example set-up, and look into this properly...

stephencookdev avatar Apr 02 '18 21:04 stephencookdev

That would be awesome, thanks!

rosenfeld avatar Apr 02 '18 21:04 rosenfeld

Sorry for the radio-silence on this one, been a hectic couple of weeks!

I've raised https://github.com/stephencookdev/speed-measure-webpack-plugin/pull/41 which should address multi-configs, and env-generated configs as first-party options

So on that branch, the following would work

module.exports = smp.wrap(env => [conf1, conf2]);

or

module.exports = env => smp.wrap([conf1, conf2]);

whichever you prefer.

I'd appreciate it if you could check out that branch, and confirm that everything works as expected for you, @rosenfeld, before I merge!

stephencookdev avatar Apr 19 '18 07:04 stephencookdev

Hmm, I need more time to test this. It basically worked as expected for one of my projects. But it finishes much before the build in the other project. Both are running webpack 4.5.0. Currently I'm on a tight deadline so it may take a while before I could investigate the differences between both configs that are causing this difference in the behavior of this plugin. Anyway, maybe it would be good to merge this since it works for some projects. Then I can open a new issue with a sample project if I can reproduce it so that it fixes the issue I'm having with this other project...

Also, I noticed, in the project for which smp worked fine, that I couldn't see the minifying time when --mode production is given to webpack. Is this expected? For the other project I use --env.production to detect the mode and always build with --mode development --env.production and use the uglify plugin manually, so maybe it would show up this time with SMP, but unfortunately I can't test it until this issue is fixed.

rosenfeld avatar Apr 19 '18 13:04 rosenfeld

I have a private project I use to bootstrap new projects and that I intend to open-source once it's more polished. I can reproduce the issue in this project. Just let me know your gitlab account and I can share it with you.

rosenfeld avatar Apr 19 '18 14:04 rosenfeld

I have a gitlab account of the same name, @stephencookdev if you want to share that :)

stephencookdev avatar Apr 19 '18 22:04 stephencookdev

I just added you to the project. You should be able to reproduce by cloning the project and:

cd front-end
yarn add --dev stephencookdev/speed-measure-webpack-plugin#41/head
scripts/build-icons

Then change webpack.config.babel.js to use SMP and you should notice that it will report before the build is finished. Just let me know if you have any questions.

rosenfeld avatar Apr 19 '18 22:04 rosenfeld

I'm using 1.3.2 of this plugin to wrap a function that returns 3 configs. The plugin throws no errors but only outputs stats based on the first config, instead of all 3. I have tried both of the formats suggested above:

module.exports = smp.wrap(env => [conf1, conf2]);

or

module.exports = env => smp.wrap([conf1, conf2]);

The solution I have settled on for now is

module.exports = env => {
  return [conf1, conf2].map(config => new smp().wrap(config));
};

Interesting note: When I didn't create a new object in the map function, the plugin still only output once, with the stats of the first config.

ZDTaylor avatar Jul 09 '20 20:07 ZDTaylor