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

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

Open
rosenfeld opened this issue Apr 2, 2018 · 10 comments

Comments

@rosenfeld
Copy link

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!

@stephencookdev
Copy link
Owner

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

@rosenfeld
Copy link
Author

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?

@stephencookdev
Copy link
Owner

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...

@rosenfeld
Copy link
Author

That would be awesome, thanks!

@stephencookdev
Copy link
Owner

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

I've raised #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!

@rosenfeld
Copy link
Author

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
Copy link
Author

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.

@stephencookdev
Copy link
Owner

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

@rosenfeld
Copy link
Author

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.

@ZDTaylor
Copy link

ZDTaylor commented Jul 9, 2020

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.

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

No branches or pull requests

3 participants