首页 > 解决方案 > 为什么lodash会在webpack中自动拆分成vendor?

问题描述

我正在使用带有反应的 webpack。在一个屏幕中导入 lodash 时,我很困惑地看到有一个供应商捆绑文件/js/vendors-node_modules_lodash_lodash_js.3715c9aa.js。我没有配置SplitChunksPlugin选项。

我的 webpack 配置文件

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    mode: "development",
    entry: './src/index.js',
    output: {
        filename: 'js/[name].[contenthash:8].js',
        path: path.resolve(__dirname, 'dist'),
        clean: true
    },
    module: {
        rules: [
            {
                test: /\.js$/i,
                use: ["babel-loader"],
                exclude: /node_modules/
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "index.html"
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        compress: true,
        port: 9000,
        host: "localhost",
        open: true,
        historyApiFallback: true,
    }
};

标签: webpack

解决方案


推荐阅读