Javascript 网页包分割块将所有内容放在一个文件中

Javascript 网页包分割块将所有内容放在一个文件中,javascript,webpack,webpack-splitchunks,Javascript,Webpack,Webpack Splitchunks,我有一个大的应用程序,我想拆分它。 目前我有以下结构: application.js < entry point Messages.js < application.js inner module SystemSetup.js < application.js inner module /node_modules/react.js < node modules Common.js < local file, used inside of Messages and S

我有一个大的应用程序,我想拆分它。 目前我有以下结构:

application.js < entry point
Messages.js < application.js inner module
SystemSetup.js < application.js inner module
/node_modules/react.js < node modules
Common.js < local file, used inside of Messages and SystemSetup
我拿到了所有的包裹,但结果不好。我有这样的档案:

Common.js < 11mb files, expected around 5mb
node_module.js < 3.7 mb < looks good
Messages.js < 7kb, expected around 3mb
SystemSetup.js < 7kb, expected around 3mb
application.js < 7kb < looks good
Common.js<11mb文件,预计约5mb
node_module.js<3.7 mb<看起来不错
Messages.js<7kb,预计约3mb
SystemSetup.js小于7kb,预计约为3mb
application.js<7kb<看起来不错

为什么没有在条目中包含
Common.js
?90%的用户只加载
Messages.js
。另外,我只想在时间上编译一个模块(当我处理消息时,我不想编译SystemSetup),很可能这将花费更少的时间。目前我有8个独立的模块,所有模块的编译大约需要3分钟。如果我使用
webpack--watch
,应用更改大约需要15秒。我希望,通过这些更改,我将能够在30秒内编译一个模块,并在5秒内使用
webpack--watch
重新编译。您使用的是Redux吗?
const path = require('path');
const WebpackNotifierPlugin = require('webpack-notifier');
const AsyncChunkNames = require('webpack-async-chunk-names-plugin');
const Profile = require('./src/js/Profile');
const production = Profile.environment === 'prod';

module.exports = {
    mode: production ? 'production' : 'development',
    entry: {
        application: './src/js/Application.js',
        Messages: './src/js/components/routes/Messages.js',
        SystemSetup: './src/js/components/routes/SystemSetup.js'
    },
    output: {
        path: path.resolve(__dirname, '../assets/js/'),
        filename: '[name].js',
        chunkFilename: '[name].js',
        publicPath: "/"
    },
    cache: true,
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: ['babel-loader']
            }
        ]
    },
    watchOptions: {
        ignored: /node_modules/
    },
    plugins: [
        new WebpackNotifierPlugin({alwaysNotify: true, title: 'Webpack JS job'}),
        new AsyncChunkNames()
    ],
    devtool: 'source-map',
    resolve: {
        alias: {
            root: path.join(__dirname, 'src/js/'),
            '~': path.resolve(__dirname, 'src/js/'),
        }
    },
    optimization: {
        splitChunks: production ? {} : {
            cacheGroups: {
                default: false,
                vendors: false,
                node_modules: {
                    name: 'node_modules',
                    chunks: 'all',
                    test: /node_modules/,
                    priority: 40
                },
                common: {
                    name: 'common',
                    minChunks: 2,
                    chunks: 'all',
                    priority: 20,
                    reuseExistingChunk: true,
                    enforce: true
                },
                Messages: {
                    name: 'Messages',
                    chunks: 'all',
                    test: /.*\/Messages\.js$/,
                    reuseExistingChunk: true,
                    priority: 30
                },
                SystemSetup: {
                    name: 'SystemSetup',
                    chunks: 'all',
                    test: /.*\/SystemSetup\.js$/,
                    reuseExistingChunk: true,
                    priority: 30
                },
            }
        }
    }
};
Common.js < 11mb files, expected around 5mb
node_module.js < 3.7 mb < looks good
Messages.js < 7kb, expected around 3mb
SystemSetup.js < 7kb, expected around 3mb
application.js < 7kb < looks good