0

I am trying to extract all the css into one file, I am using webpack2 and i have extract-text-webpack-plugin@2.0.0-rc.0, the following is my code

webpack

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


module.exports = {
    entry: './app/main.ts',
    output: {
        path: './dist',
        filename: 'app.bundle.js'
    },
    module: {
        rules: [
            { test: /\.ts$/, exclude: /node_modules/, use: ['ts-loader'] },
            { test: /\.css$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader', publicPath: "./dist" }) }
        ]

    },
    resolve: {
        extensions: ['.js', '.ts']
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html',
            minify: {
                collapseWhitespace: true
            },
        }),
        new ExtractTextPlugin({
            filename: 'style.css',
            disabled: false,
            allChunks: true
        })
    ]
};

package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",  
  "keywords": [],
  "author": "",
  "license": "MIT", 
  "devDependencies": {    
    "css-loader": "^0.28.0",    
    "extract-text-webpack-plugin": "^2.0.0-rc.0",    
    "html-webpack-plugin": "^2.28.0",    
    "style-loader": "^0.16.1",
    "ts-loader": "^2.0.3",
    "tslint": "^3.15.1",
    "typescript": "~2.0.10",
    "typings": "^2.1.1",    
    "webpack": "2.2.1"
  },
  "repository": {}
}

main.ts

require('../app/content/custom.css');
import 'core-js';
import 'reflect-metadata';
import 'zone.js/dist/zone';

import { enableProdMode } from '@angular/core'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);

when i try to run the webpack, i get the following error

enter image description here I was following this tutorial for building webpack webpack tutorial

Lijin Durairaj
  • 3,341
  • 11
  • 31
  • 50

1 Answers1

0

First you can safely remove the const webpack = require('webpack') from your webpack.config.js, it's not needed :)

Could you try to without publicPath: './dist' && use: ['css-loader'] instead of use: 'css-loader' in ExtractTextPlugin.extract() ?