0

I took the Webpack tutorial from Angular.io and started to upgrade to Webpack 2 following the official and a not official guide.

I met the error below:

ERROR in ./public/css/styles.css Module parse failed: DashboardDelivery.Host.Ui.Spa\public\css\styles.css Unexpected character '#' (3:16) You may need an appropriate loader to handle this file type. | body | { | background: #0147A7; | color: #fff; | }

  • I don't get what the problem is
  • if the file empty then it throws an error where text.Foreach is unknown function
  • if only an empty body{} in the css file then webpack complains body is not defined

Basically, doesn't matter what I do there is always an issue and the character related is the most strange. What I'm missing here?

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;
}
AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77

1 Answers1

1

After a few grinding hours to find answer there is an answer... ExtractTextPlugin doesn't work with the new use syntax. Here is the blog I found the suggestion, and here is the bug ticket.

AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77