0

我正在尝试将所有 css 提取到一个文件中,我正在使用 webpack2 并且我有 extract-text-webpack-plugin@2.0.0-rc.0,以下是我的代码

网页包

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
        })
    ]
};

包.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);

当我尝试运行 webpack 时,出现以下错误

在此处输入图像描述 我正在按照本教程构建 webpack webpack 教程

4

1 回答 1

0

首先,您可以安全地const webpack = require('webpack')从您的 中删除webpack.config.js,这不是必需的 :)

您可以尝试不使用publicPath: './dist'&&use: ['css-loader']而不是use: 'css-loader'inExtractTextPlugin.extract()吗?

于 2017-05-05T01:55:11.247 回答