Code Monkey home page Code Monkey logo

Comments (5)

wywzixin avatar wywzixin commented on June 1, 2024

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

from happypack.

amireh avatar amireh commented on June 1, 2024

Can you list your Webpack version and the config?

from happypack.

wywzixin avatar wywzixin commented on June 1, 2024

[email protected]
"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;
},

};

from happypack.

wywzixin avatar wywzixin commented on June 1, 2024

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

from happypack.

MyCodeMyWorld avatar MyCodeMyWorld commented on June 1, 2024

Has the problem been solved?

from happypack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.