sasswebpackextract-text-plugin

extract text plugin not extracting css from .scss


I have the following webpack.cofig.js file

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: {
    app: './src/main.ts',
    polyfills: './src/polyfills.ts'
  },
  output: {
    path: path.resolve('dist'),
    filename: '[name].js',
    publicPath: 'assets/'
  },
  resolve: {
    // only discover files that have those extensions
    extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html'],
  },
  module: {
    rules: [{
      test: /\.ts$/,
      exclude: /node_modules/,
      loader: 'awesome-typescript-loader'
    },
    {          
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ['css-loader', 'sass-loader']
      })
    },
    {
      test: /\.html$/,
      loader: 'html-loader'
    },
    {
      test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
      loader: 'file-loader?name=fonts/[name].[hash].[ext]?'
    }
    ]
  },
  plugins: [       
    new ExtractTextPlugin({ filename: 'mystyle.css', disable: false, allChunks: true })
  ]
};

However when I run this, the css file that should be generated does not appear. I am using extract-text-webpack-plugin however this does not work. It does not throw an error, however it does not work either.


Solution

  • Ok I got this to work, the reason was that in my root app component (angular2) I had the following for referring to the main stylesheet.

      styleUrls: ['./app.component.scss'],
    

    This worked fine even without the scss loader (I am using the awesome typescript loader). However when I included the following

    const styles = require('./app.component.scss');
    

    Then the additional css got generated.