amireh / happypack

Happiness in the form of faster webpack build times.
MIT License
4.24k stars 124 forks source link

unable to locate the plugin list! This most likely indicates an internal error. #273

Open wywzixin opened 4 years ago

wywzixin commented 4 years ago

微信截图_20200927203739

wywzixin commented 4 years ago

I don't know what happened to it. Can you help me look at it

amireh commented 4 years ago

Can you list your Webpack version and the config?

wywzixin commented 4 years ago

webpack@4.44.2 "happypack": "^5.0.1", use vue-cli4

const path = require('path'); const webpack = require('webpack'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const UglifyJsPlugin = require('terser-webpack-plugin'); const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin'); const CompressionPlugin = require('compression-webpack-plugin'); const HappyPack = require('happypack') const os = require('os') const ProgressBarPlugin = require('progress-bar-webpack-plugin'); const chalk = require('chalk'); const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length })

const isProd = process.env.NODE_ENV === 'production'; module.exports = { publicPath: isProd ? ' ./' : '/', devServer: { }, configureWebpack: config => { config.module.unknownContextCritical = false; config.resolve.alias = { '@': path.resolve(dirname, 'src'), C: path.resolve(dirname, 'src/components'), S: path.resolve(dirname, 'src/service'), U: path.resolve(dirname, 'src/utils'), }; config.entry = isProd ? { customSource: './src/CustomSource/CustomSource.js', app: './src/main.js', } : { Cesium: './ThirdParty/CesiumSource.js', customSource: './src/CustomSource/CustomSource.js', app: './src/main.js', };

    config.plugins.push(
        new webpack.DefinePlugin({
            CESIUM_BASE_URL: JSON.stringify('./Cesium/')
        }),
        new CopyWebpackPlugin([
            {
                from: './node_modules/cesium/Build/Cesium',
                to: 'Cesium',
            },
        ]),
        new webpack.ProvidePlugin({
            jQuery: 'jquery',
            $: 'jquery',
        }),
        new HappyPack({
            id: 'happyBabel',
            loaders: [{
                loader: 'babel-loader?cacheDirectory=true',
            }],
            threadPool: happyThreadPool,
            verbose: true,
        })
    );

    if (isProd) {
        config.module.rules.push({
            test: /\.js$/,
            loader: 'happypack/loader?id=happyBabel',
            exclude: /node_modules/
        });
        // 为生产环境修改配置...
        config.optimization = {
            minimizer: [
                new UglifyJsPlugin({
                    terserOptions: {
                        warnings: false,
                        compress: {
                            drop_debugger: true,
                            drop_console: true,
                            pure_funcs: ['console.log'],
                        },
                        output: {
                            comments: false,
                        },
                    },
                    sourceMap: false,
                    parallel: true,
                }),
            ],
            splitChunks: {
                chunks: 'all',
                minSize: 300000,
                maxSize: 10000000,
                cacheGroups: {
                    vendors: {
                        test: /[\\/]node_modules[\\/]/, // 匹配node_modules目录下的文件
                        priority: -10, // 优先级配置项
                    },
                    default: {
                        minChunks: 2,
                        priority: -20, // 优先级配置项
                        reuseExistingChunk: true,
                    },
                },
            },
        };
        config.plugins.push(
            new HtmlWebpackPlugin({
                filename: './index.html',
                template: './public/index.html',
            }),

            new HtmlWebpackTagsPlugin({
                append: false,
                scripts: 'Cesium/Cesium.js',
            }),

            new HtmlWebpackTagsPlugin({
                append: false,
                links: 'Cesium/Widgets/widgets.css',
            }),
            // new BundleAnalyzerPlugin(),
            new CompressionPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                test: /\.js$|\.css$|\.html$/,
                threshold: 102400,
                minRatio: 0.8,
                deleteOriginalAssets: true,
            }),
            // new HappyPack({
            //     // 3) re-add the loaders you replaced above in #1:
            //     loaders: [ 'babel-loader?presets[]=es2015' ],
            //     threadPool: happyThreadPool,
            //     id: 'babel'
            //   }),
            // new HappyPack({
            //     //用id来标识 happypack处理那里类文件
            //     id: 'happyBabel',
            //     //如何处理  用法和loader 的配置一样
            //     loaders: [{
            //         loader: 'babel-loader?cacheDirectory=true',
            //     }],
            //     //共享进程池
            //     threadPool: happyThreadPool,
            //     //允许 HappyPack 输出日志
            //     verbose: true,
            // }),
            new ProgressBarPlugin({
                format: ' build [:bar] ' + chalk.green.bold(':percent') + ' (:elapsed seconds)',
                clear: false
            })
        );
    } else {
        // 为开发环境修改配置...
        config.devtool = 'eval-source-map';
        config.plugins.push(
            new HtmlWebpackPlugin({
                filename: './index.html',
                template: './public/index.html',
            }),
            new HtmlWebpackTagsPlugin({
                append: false,
                links: './Cesium/Widgets/widgets.css',
            })
        );
    }
},
chainWebpack: config => {
    const oneOfsMap = config.module.rule('scss').oneOfs.store;
    oneOfsMap.forEach(item => {
        item.use('sass-resources-loader')
            .loader('sass-resources-loader')
            .options({
                resources: './src/style/public.scss',
            })
            .end();
    });
    config
        .plugin('webpack-bundle-nalyzer')
        .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin);
    return config;
},

};

wywzixin commented 4 years ago

Can you list your Webpack version and the config? Is it a version issue?

MyCodeMyWorld commented 2 years ago

Has the problem been solved?