0

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.

4

1 回答 1

1

好的,我让它工作了,原因是在我的根应用程序组件(angular2)中,我有以下引用主样式表的内容。

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

即使没有 scss 加载器,这也能正常工作(我正在使用很棒的 typescript 加载器)。但是,当我包含以下内容时

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

然后生成了额外的css。

于 2017-05-07T22:14:36.877 回答