Html-webpack-plugin: How to add styles

Created on 2 Dec 2014  路  6Comments  路  Source: jantimon/html-webpack-plugin

  module: {
    loaders: [
        {
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract("style", "css!sass")
        },


plugins: [
    new ExtractTextPlugin("style.[hash].css", {
        allChunks: true
    }),
    new HtmlWebpackPlugin({
        template: 'src/client/index.html',
        "assets": {
            "client" : "client.[hash].js",
            "style"  : "style.[hash].css",
        }
    })
]

template:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <title>My App</title>
  </head>
  <body>
    <link href="{%=o.htmlWebpackPlugin.assets.style%}" media="all" rel="stylesheet" type="text/css">
    <script src="{%=o.htmlWebpackPlugin.assets.client%}"></script>
  </body>
</html>

Most helpful comment

I think this could use some more explicit documentation. Especially in the use case of multiple chunks going to the the head and/or body.

All 6 comments

try:

<link rel="stylesheet" href="[prepend_your_public_path/]{%=o.webpack.assetsByChunkName.client[1]%}">

more details here: https://github.com/ampedandwired/html-webpack-plugin/issues/1

Thanks @bitplanets, some good ideas there, and apologies for not getting back to you sooner. I'm going to put a bit of work into making this a bit easier, as well as addressing the script ordering problem.

The pull-request #14 supports the ExtractTextPlugin

@jantimon's PR #14 allows for styles to be included, so closing this for now. Let me know if this doesn't meet your needs.

I think this could use some more explicit documentation. Especially in the use case of multiple chunks going to the the head and/or body.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NeverwinterMoon picture NeverwinterMoon  路  3Comments

lonelyclick picture lonelyclick  路  3Comments

amorphius picture amorphius  路  3Comments

hp8wvvvgnj6asjm7 picture hp8wvvvgnj6asjm7  路  3Comments

lonelydatum picture lonelydatum  路  3Comments