Angular 5 + Webpack 3.6.0 + AOT:“在没有相应插件的情况下使用加载程序”时,extract-text-webpack-plugin失败

时间:2018-11-11 21:22:23

标签: angular webpack aot extracttextwebpackplugin

我遇到的是带有Webpack 3.6.0的Angular 5(使用AOT进行生产构建)的问题。对于CSS,我突然使用extract-text-webpack-plugin在以下eo上开始失败:

  

模块构建中的错误失败:错误:使用“ extract-text-webpack-plugin”加载程序而没有相应的插件,使用示例请参考https://github.com/webpack/extract-text-webpack-plugin       在Object.pitch(/ Users /.../ node_modules / extract-text-webpack-plugin / dist / loader.js:53:11)

这是我的生产配置:

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require('path');
const ngToolsWebpack = require('@ngtools/webpack');

const ENV = process.env.NODE_ENV = process.env.ENV = 'prod';


module.exports = {
    entry: {
        'polyfills': './polyfills.ts',
        'vendor': './vendor.ts',
        'app': './app/main-aot.ts'
    },
    resolve: {
        extensions: ['.ts', '.js', '.json']
    },
    output: {
        path: path.join(__dirname, 'wwwroot'),
        filename: 'js/[name].[hash:6].bundle.js',
        chunkFilename: 'js/[id].[hash:6].chunk.js'
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: '@ngtools/webpack'
            },
            {
                test: /\.html$/,
                use: 'html-loader'
            },
            // {
            //     test: /\.(png|jpg|gif|ico|woff|woff2|ttf|svg|eot)$/,
            //     use: 'file-loader?name=assets/[name]-[hash:6].[ext]',
            // },
            {
                test: /\.(png|jpe?g|gif|ico)$/,
                use: 'file-loader?name=assets/[name].[ext]',
            },
            { test: /\.(woff2?|ttf|eot|svg)$/,
                use: 'url-loader'
            },
            {
                test: /\.css$/,
                exclude: path.resolve(__dirname, "app"),
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader', use: [
                        { loader: 'css-loader', options: { minimize: true } }
                    ]
                })
            },
            {
                test: /\.css$/,
                include: path.resolve(__dirname, "app"),
                use: 'raw-loader'
            }
        ]
    },
    plugins: [
        // AoT plugin.
        new ngToolsWebpack.AngularCompilerPlugin({
            tsConfigPath: './tsconfig-aot.json'
        }),
        new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.optimize.CommonsChunkPlugin({
            name: ['app', 'vendor', 'polyfills']
        }),
        new CleanWebpackPlugin(
            [
                './wwwroot/js/',
                './wwwroot/css/',
                './wwwroot/assets/',
                './wwwroot/index.html'
            ]
        ),
        new CopyWebpackPlugin([
            { from: './assets', to: './assets' },
        ]),
        // inject in index.html
        new HtmlWebpackPlugin({
            template: './index.html',
            inject: 'body',
            filename: 'index.html'
        }),
        new ExtractTextPlugin('css/[name]-[hash:6].bundle.css'),
        new webpack.DefinePlugin({
            'process.env': {
                'ENV': JSON.stringify('prod')
            }
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            },
            output: {
                comments: false
            },
            sourceMap: false
        }),
        new webpack.ProvidePlugin({
            jQuery: 'jquery',
            $: 'jquery',
            jquery: 'jquery'
        })
    ]
};

我正在运行以下命令进行构建:

rm -rf .aot wwwroot node_modules/ && npm cache clean -f && npm install && npm run ngc && npm run build:dist

有人可以帮我吗?确实需要进行生产构建,但是我遇到了麻烦。谢谢。

0 个答案:

没有答案