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

Differentiate css and js for template in chunks #69

Open
rajar-r opened this issue Feb 20, 2018 · 3 comments
Open

Differentiate css and js for template in chunks #69

rajar-r opened this issue Feb 20, 2018 · 3 comments

Comments

@rajar-r
Copy link

rajar-r commented Feb 20, 2018

on using this below all the chunks including css are also added as script html tag element rather than css tag element. how to add css with link tag and js with script tag using chunks.

<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>

<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>

<% } %>

Also tried using below , but this include the css as well.

<% for (var chunk in htmlWebpackPlugin.files.js) { %>

<script src="<%= htmlWebpackPlugin.files.js[chunk]%>"></script>

<% } %>

@phiphou
Copy link

phiphou commented Mar 25, 2018

Same for me, need information.

@jaketrent
Copy link
Owner

I'm not sure that I know what is going on here. Please offer me some code or something more concrete about the problem you're having.

As I understand it, webpack is producing js files by default. These chunks will show up here, as you've mentioned:

https://github.com/jaketrent/html-webpack-template/blob/master/index.ejs#L104

If you're producing .css files, you're probably using ExtractTextPlugin or something like that and then will get css files here, right?:

https://github.com/jaketrent/html-webpack-template/blob/master/index.ejs#L48

@phiphou
Copy link

phiphou commented Mar 28, 2018

You can use inject: true, and get rid of

<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
    <script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>

or use htmlWebpackPlugin.files.chunks for js and htmlWebpackPlugin.files.css for styles

<% for (var chunk in htmlWebpackPlugin.files.js) { %>
    <script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry%>"></script>
<% } %>

and

<% for (var style in htmlWebpackPlugin.files.css) { %>
    <script src="<%= htmlWebpackPlugin.files.css[style]%>"></script>
<% } %>

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