为什么css-loader / style-loader会抛出意外的字符#error?

时间:2017-01-20 20:14:48

标签: css webpack webpack-style-loader

我从Angular.io获取了Webpack教程,并在官方和not official指南之后开始升级到Webpack 2。

我遇到了以下错误:

  

./public/css/styles.css中的错误       模块解析失败:DashboardDelivery.Host.Ui.Spa \ public \ css \ styles.css意外   人物'#' (3:16)       您可能需要适当的加载程序来处理此文件类型。       |体       | {       |背景:#0147A7;       |颜色:#fff;       | }

  • 我没有解决问题
  • 如果文件为空则会抛出错误,其中text.Foreach是未知函数
  • 如果css文件中只有空体{},则webpack抱怨主体未定义

基本上,无论我做什么都不重要,总有一个问题,而且相关的角色最奇怪。我在这里失踪了什么?

webpack.common.js

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');

module.exports = {
    entry: {
        'polyfills': './src/app/polyfills.ts',
        'vendor': './src/app/vendor.ts',
        'app': './src/app/main.ts'
    },

    resolve: {
        extensions: ['.ts', '.js']
    },

    module: {
        rules: [
          {
              test: /\.ts$/,
              use: ['awesome-typescript-loader', 'angular2-template-loader']
          },
          {
              test: /\.html$/,
              use: 'html-loader'
          },
          {
              test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
              use: 'file-loader?name=assets/[name].[hash].[ext]'
          },
          {
              test: /\.css$/,
              exclude: helpers.root('src', 'app'),
              use: ExtractTextPlugin.extract(
                  {
                      fallbackLoader: 'style-loader',
                      loader: 'css-loader?sourceMap',
                      publicPath: "/dist"
                  })
          },
          {
              test: /\.css$/,
              include: helpers.root('src', 'app'),
              use: 'raw-loader'
          }
        ]
    },

    plugins: [
      new webpack.optimize.CommonsChunkPlugin({
          name: ['app', 'vendor', 'polyfills']
      }),

      new HtmlWebpackPlugin({
          template: 'src/index.html'
      }),

    ]
};

webpack.dev.js

var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');

module.exports = webpackMerge(commonConfig, {
    devtool: 'cheap-module-eval-source-map',

    output: {
        path: helpers.root('dist'),
        publicPath: 'http://localhost:8080/',
        filename: '[name].js',
        chunkFilename: '[id].chunk.js'
    },

    plugins: [
      new ExtractTextPlugin('[name].css')
    ],

    devServer: {
        historyApiFallback: true,
        stats: 'minimal'
    }
});

的style.css

body 
{
    background: #0147A7;
    color: #fff;
}

1 个答案:

答案 0 :(得分:1)

几个小时后找到答案有答案...... ExtractTextPlugin不能使用新的使用语法。以下是blog我找到了建议,这是错误ticket