Webpack:不产生预期的捆绑

时间:2018-09-17 20:41:33

标签: javascript webpack webpack-4

好吧,正如标题所述,webpack并没有达到我的期望。

这是我的配置:

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

const extractPlugin = new ExtractTextPlugin({
    filename: 'main.css',
});

process.env.NODE_ENV = 'production';

module.exports = {
    entry: {
        main: './src/main.js',
        algo: './src/algo.js',
    },
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].js',
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: ['es2015'],
                        }
                    }
                ],
            },
            {
                test: /\.scss$/,
                use: extractPlugin.extract({
                    use: [
                        'css-loader',
                        'sass-loader',
                    ]
                })
            },
            {
                test: /\.html$/,
                use: ['html-loader']
            },
            {
                test: /\.php$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[path][name].[ext]',
                            outputPath: '/'
                        }
                    }
                ]
            },
            {
                test: /\.(jpg|png|gif|jpeg)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[path][name].[ext]',
                            outputPath: 'images/',
                        }
                    }
                ]
            }
        ],
    },
    resolve: {
        alias: {
            vue: 'vue/dist/vue.min'
        }
    },
    plugins: [
        extractPlugin,
        new HtmlWebpackPlugin({
            template: 'src/index.html',
            filename: 'index.html',
            chunks: ['main'],
        }),
        new HtmlWebpackPlugin({
            template: 'src/algo.html',
            filename: 'algo.html',
            chunks: ['algo']
        }),

        new CleanWebpackPlugin([
            'dist',
        ]),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            Vue: 'vue',
        }),
        new CopyWebpackPlugin([
            {
                from: 'src/*.php',
                to: '[name].[ext]',
                test: /\.php$/
            }
        ]),
    ],
    mode: 'production',
};

main.jsalgo.js都只是一组@import 'something'(请在注释中告诉我这是否是一种好习惯)。

我要插入生成的包main.jsalgo.js进入 index.htmlalgo.html

但是,到目前为止,它只为main.js生成了index.html

以前,output如下:

output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
},

但是,那也不起作用。

有人可以帮助我达到预期的结果吗?

1 个答案:

答案 0 :(得分:2)

您在配置中指定了Microsoft C++ exception: winrt::hresult_wrong_thread at memory location 0x00000040E4EFE6E8 两次

entry

这里的第二个entry: { main: './src/main.js', algo: './src/algo.js', }, entry: './src/main.js', 覆盖第一个,这意味着您仅配置了entry