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

Multiple bundles #1

Closed
nickdima opened this issue Oct 2, 2014 · 5 comments
Closed

Multiple bundles #1

nickdima opened this issue Oct 2, 2014 · 5 comments

Comments

@nickdima
Copy link

nickdima commented Oct 2, 2014

I have a use case where I'm using the ExtractTextPlugin for generating a css file. In this case there's an extra bundle generated for the same chunk (one js file and one css file).
Looking at the code I see that you're just taking the first element when the chunk is an array, but with my use case I would need to get access to the second item which is the css file.
The ideal option here would be to get the specific item from the array by specifying the index in the template, like this: {%=o.htmlWebpackPlugin.assets.styles[1]%} and fallback to the first item when not specifying an index.
With the current codebase this doesn't seem doable, as you just pass the data structure to the template engine.
Any thoughts? For my own use I just changed it so you always need to specify the index when the chunk is an array, but this won't work when switching back and forth between building with and without source maps.

@ampedandwired
Copy link
Collaborator

You can always access the underlying webpack stats object via o.webpack. So in your case you should be able to get a handle on the css using {%=o.webpack.assetsByChunkName.styles[1]%}. You'll have to manually prepend the public path though if you're using one.

The o.htmlWebpackPlugin.assets object was really only ever intended to be a bit of sugar for simple use cases - it's simply a repackaging of what's in stats.assetsByChunkName, with a few niceties such as prepending the public path for you.

I can see how exposing the all the assets as an array might be useful though. Will put some thought into how it could be handled.

@Kagami
Copy link

Kagami commented Dec 1, 2014

👍
@ampedandwired I think it would be great to include all generated stylesheets in the index.html as well in default template.

@jantimon
Copy link
Owner

The pull request #14 adds all ExtractTextPlugins to the head element

@ampedandwired
Copy link
Collaborator

Closing this now that #14 is merged. All generated css is now included in the default index.html, and details of the css files (per chunk and globally) are available in the htmlWebpackPlugin.files object.

@lock
Copy link

lock bot commented Jun 1, 2018

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants