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

Multi config webpack to use same template #1051

Closed
gaje opened this issue Sep 21, 2018 · 9 comments
Closed

Multi config webpack to use same template #1051

gaje opened this issue Sep 21, 2018 · 9 comments
Labels

Comments

@gaje
Copy link

gaje commented Sep 21, 2018

If i have a multiple config webpack (https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations), I'm looking for a way to be able to share a common template and inject all assets built by all configurations into the same template.

Currently, the template just gets overwritten.

Use case: I am trying to generate two separate bundles: modern and legacy (one gets loaded via type="module" other uses nomodule attribute. I need to be able to run different babel configurations against these, so i need to use separate configs - but i want both assets to be included into the same template

@goodmind
Copy link

any updates?

@ghost
Copy link

ghost commented Nov 23, 2018

I'd also appreciate such a feature

@jantimon
Copy link
Owner

I am not sure if a webpack plugin can be shared for multiple instances.
@Sparki2002 @goodmind @gaje could you please try to find out if thats possible?

@davilima6
Copy link

davilima6 commented Feb 23, 2019

I don't know if a plugin instance can be shared but, discussing another approach, what if filename is the same in multiple plugin instances but we add an update boolean option like in assets-webpack-plugin? Do you think it'd be possible having multiple compilations incrementally writing the file?

I'm not sure whether we'd get race conditions (e.g. can't open file for write) because from my tests multi-target compilation is async. I can't say if one waits the other to be finished but at minimum you cannot guarantee the order in which each compilation happens, when you tap into done hook for inspection, for example (even though it's only documented developer should input them as an array, which hints to another expectation, shrugs). Anyway that's the approach suggested in https://calendar.perfplanet.com/2018/doing-differential-serving-in-2019/ And also discussed in gatsbyjs/gatsby#2114


PS: Here are two example of working around the absence of this flag, tapping into htmlWebpackPluginBeforeHtmlGeneration and htmlWebpackPluginAlterAssetTags, htmlWebpackPluginAfterHtmlProcessing hooks in the first case and htmlWebpackPluginAlterAssetTags and htmlWebpackPluginAfterHtmlProcessing only in the other:

They also change link and script tags attributes (and both inject a safari 10 fix) and I understand html-webpack-plugin prefers doing One Thing Only so I'm currently relying on script-ext-html-webpack-plugin but may change that.

@davilima6
Copy link

davilima6 commented Feb 23, 2019

Even though I do support adding such flag I should say I'm currently outputting to different files in each config and plan to use user agent sniffing at Nginx or backend to serve the safe version because the type="module" + nomodule strategy is pretty limited and hits my use case. For example, the two latest versions of Edge (17-18 currently) do not handle it correctly and execute three (!) downloads: one nomodule and twice the same module one 🤦‍♂️ See: philipwalton/webpack-esnext-boilerplate#1 (comment) and https://twitter.com/benjamn/status/1005104014944538624

@stale
Copy link

stale bot commented Aug 22, 2019

This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.

@stale stale bot added the wontfix label Aug 22, 2019
@nishant-labs
Copy link

I would love to have this feature, specially when I need to get asset files generated by array of configuration passed to webpack.
Also it will be great if that is available in assets parameter in templateParameters function as well.

@stale stale bot removed the wontfix label Sep 5, 2019
@sshrshnv
Copy link

Is there any progress?

@stale
Copy link

stale bot commented Aug 24, 2020

This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.

@stale stale bot added the wontfix label Aug 24, 2020
@stale stale bot closed this as completed Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants