-
Notifications
You must be signed in to change notification settings - Fork 37
Optimizing webpack build with babel & babili #8
Comments
babel/minify#162 is merged .. |
Just for your information: With babel/minify#162 shipped, we can now pass options to Babili through the new BabiliWebpackPlugin({
babili: {
presets: [
[
require('babel-preset-babili'),
{
mangle: { topLevel: true },
deadcode: false,
removeConsole: process.env.NODE_ENV === 'production',
},
],
],
plugins: [
'transform-inline-environment-variables',
],
},
}), |
I've tried setting up my webpack plugin config as above, but I still end up with compiled code that is actually larger than just using Currently this will produce bundles... .babelrc
webpack.config.js //...
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test : /\.js$|\.jsx$/,
exclude : [
/node_modules/,
/\.spec\.js$/
],
loaders : [
'babel-loader',
'eslint-loader'
],
},
],
},
plugins: [
new BabiliPlugin({
test: /\.js$|\.jsx$/,
babili: {
presets: [
[
require('babel-preset-babili'),
{
mangle: { topLevel: true },
deadcode: false,
removeConsole: true,
},
],
],
},
}),
],
//... |
I'm having the same issue as @icd2k3, the plugin is not doing any basic minification (whitespace removal). It does seem to be running, since I am using typescript so I need to pass I'm not trying to do any custom configurations, just get basic minification working. Any idea why it would run without error but fail to minify? The files are React + es6 + typescript. |
(I should add that I did not include a .babelrc file in my project since from your docs it seems like I can just used the options/overrides objects in the plugin.) |
Yes for me the minify of variables and what not is happening but agree that white space not getting stripped |
@boopathi There is a confusion.. Below works.
But it doesn't conform to the README.md What's the correct way of using it as per latest version? Can you please help! |
Is there really a reason to use this strategy? |
@boopathi Coming here from the README, and reading through the comments in this thread, I am still unclear on what strategy is recommended? Since the plugin has seen changes in the year since the thread started, could you suggest your current recommendations? Thank you! |
The defaults are work fine and the why section of the readme explains the benefits of doing the minification at the end (works on the entire output and uses ES6 parsing). Below is an example of what we run to generate an optimized bundle while including all the polyfills for the minimum browsers you want to support: webpack.config.js const path = require('path');
const webpack = require('webpack');
const BabelMinifyPlugin = require('babel-minify-webpack-plugin');
module.exports = (env) => {
return [
{
context: __dirname,
entry: { app: [path.join(__dirname, 'index.js')] },
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/, loader: ['babel-loader'] },
]
},
output: {
path: path.join(__dirname, './dist'),
filename: '[name].js'
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new BabelMinifyPlugin()
]
}
];
}; .babelrc {
"presets": [
[
"env",
{
"targets": {
"browsers": [ "safari 10", "ie 11", "ios 9" ]
},
"modules": false,
"useBuiltIns": true
}
]
],
"plugins": [
"transform-runtime"
],
"comments": false
} Include the statement Note that this will include polyfills you might not be using because those are added to the global scope and won't be removed as part of the dead code elimination. If that's a big deal, then remove the import statement described above and add in the polyfills manually. You can use the debug output for babel minify to get a list of polyfills that might be needed for your browser requirements. |
The current build sequence for a typical webpack project is
transpile -> bundle -> minify
. As babili doesn't traverse through Objects and its properties (yet), there will not be much optimizations on the bundler generated code(modules[moduleId].call())
other than mangling and whitespace/comments removal. The pipeline can be transformed to(transpile + minify) -> bundle
- if the bundler already produces mangled and has an option to output minified (just the syntax and comments) code. But, we could already do this now -The text was updated successfully, but these errors were encountered: