मैं वेबपैक बनाने की कोशिश करता हूं tree-shaking अप्रयुक्त babel-polyfill
हटाएं।वेबपैक पेड़-हिलाने से अप्रयुक्त बेबेल-पॉलीफिल हटा सकते हैं?
index.js
फ़ाइल है:
import 'babel-polyfill'
const add4 = n => n + 4
const add5 = n => n + 5
add4(6)
console.log('boom', add4(4))
इस फ़ाइल में कोई कोड किसी भी es2015 + polyfill की आवश्यकता होती है, तो मैं उम्मीद बंडल उत्पादन में अप्रयुक्त कोलाहल-polyfills दूर करने के लिए पेड़ को हिला। यह मामला नहीं है, और बंडल में अभी भी उन्हें शामिल किया गया है (minified)।
Here is a git repo with this code।
webpack config:
const MinifyPlugin = require('babel-minify-webpack-plugin')
module.exports = {
entry: './index.js',
output: {
filename: 'bundle-webpack.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new MinifyPlugin({ mangle: { topLevel: true } }, { comments: false })
]
}
और .babelrc
:
{
"presets": [
[
"env",
{
"targets": {
"browsers": ["chrome >= 50", "iOS >= 10", "ie >= 8"]
},
"useBuiltIns": true,
"modules": false,
"loose": true
}
]
]
}
मैं uglifyjs-webpack-plugin
साथ को बदलने के लिए करने की कोशिश की है, लेकिन यह एक ही परिणाम दे दी है।
पेड़-हिलाने का काम कैसे करना संभव है, और आउटपुट में babel-polyfills
नहीं है जो मूल कोड में उपयोग नहीं किया जाता है?