2 个回答

本质上,你是想使用 Webpack 的 Tree Shaking 特性。只是露珠使用 lodash-webpack-plugin 的姿势有点不正确而已。

安装了 lodash-webpack-plugin 还需要额外安装 babel-plugin-lodash

然后你在 webpack 配置中配置就可以对应的使用:

const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');

module.exports = {
    module: {
        rules: [
            {
                use: 'babel-loader',
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                options: {
                    plugins: [
                        'lodash',
                        ...
                    ],
                    ...
                }
            }
        ]
    },
    
    plugins: [
        new LodashModuleReplacementPlugin(),
        ...
    ]
};

关键是你代码里是怎么用lodash的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题