我是babel / webpack新手,我受命减小Lodash捆绑包的大小。我或多或少了解了如何插入简单的插件和更改,但是无论出于何种原因,babel-plugin-lodash
的响应方式都不相同lodash-webpack-plugin
。我觉得我只是一个小失误,无法按预期工作。
我正在使用Babel 7+版本和Webpack 4+版本
在webpack.config.js中
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
query: {
presets: [
["@babel/preset-env", {
"targets": { "node": 6 },
}],
"@babel/preset-react"
],
plugins: [
['styled-components', { displayName: true } ],
'lodash'
]
}
}
},
在.babelrc中
{
"presets": [
["@babel/preset-env", { "targets": { "node": 6 } }],
"@babel/preset-react"
],
"plugins": [
"lodash",
"transform-class-properties",
["styled-components", { "displayName": true }],
"@babel/plugin-proposal-object-rest-spread",
[ "@babel/transform-runtime", { "regenerator": true }],
]
}