本质上,你是想使用 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(), ... ] };
本质上,你是想使用 Webpack 的 Tree Shaking 特性。只是露珠使用
lodash-webpack-plugin
的姿势有点不正确而已。安装了
lodash-webpack-plugin
还需要额外安装babel-plugin-lodash
。然后你在 webpack 配置中配置就可以对应的使用: