Friday 21 April 2017

Basic Webpack ExtractTextWebpackPlugin configuration

I have a problem configuring ExtractTextWebpackPlugin for simpy including separate CSS files in my HTML head tag (using link tag), which is its main purpose i believe.

My current configuration in webpack.config.js:

var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  entry: './app/index.js',
  output: {
    filename: "app.js",
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('general.css')
  ]
};

In my main index.js file i have require("../style.css");

style.css is placed in project root folder.

In my index.html i have <script src="dist/app.js"></script>

As i understand this should inlclude general.css in my head tag at runtime but it is not there.

Any help is appreciated.



via Tetra

No comments:

Post a Comment