GithubHelp home page GithubHelp logo

Comments (10)

oyeanuj avatar oyeanuj commented on July 28, 2024 9

@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!

from babel-minify-webpack-plugin.

aseem2625 avatar aseem2625 commented on July 28, 2024 1

@boopathi There is a confusion..
This used to work as of version "babili-webpack-plugin": "0.0.11". It has stopped working now. I don't want to have .babelrc file and trying with this also doesn't help

Below works.

    new BabiliPlugin({
      mangle: { 'topLevel': true },
      deadcode: true
    }),

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!

from babel-minify-webpack-plugin.

manigandham avatar manigandham commented on July 28, 2024 1

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 import 'babel-polyfill'; in your code (only once, like in your entry script file) and Babel will take care of the rest by adding the appropriate polyfills for all the browser requirements you have, and then bundling and minifying the entire output as a whole.

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.

from babel-minify-webpack-plugin.

boopathi avatar boopathi commented on July 28, 2024

babel/minify#162 is merged ..

from babel-minify-webpack-plugin.

nodaguti avatar nodaguti commented on July 28, 2024

Just for your information:

With babel/minify#162 shipped, we can now pass options to Babili through the babili property like this:

new BabiliWebpackPlugin({
  babili: {
    presets: [
      [
        require('babel-preset-babili'),
        {
          mangle: { topLevel: true },
          deadcode: false,
          removeConsole: process.env.NODE_ENV === 'production',
        },
      ],
    ],
    plugins: [
      'transform-inline-environment-variables',
    ],
  },
}),

from babel-minify-webpack-plugin.

icd2k3 avatar icd2k3 commented on July 28, 2024

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 uglify-webpack-plugin... Any ideas of things I could try? I've tried lots of combinations of config/babelrc but each produces a build larger than that of uglify which doesn't seem right?

Currently this will produce bundles...
Uglify: 325.1kb
Bibili: 339.4kb

.babelrc

{
  "presets": [
    [
      "es2015",
      {
        modules: false
      }
    ],
    "es2017",
    "react",
    "stage-0",
  ],
  "plugins": [
    "transform-object-assign"
  ],
  "env": {
    "production": {
      "presets": ["babili"]
    }
  }
}

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,
            },
          ],
        ],
      },
    }),
  ],
//...

from babel-minify-webpack-plugin.

mosesoak avatar mosesoak commented on July 28, 2024

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 test: /\.tsx?$/, in the 2nd parameter for 'overrides' to get it to run without error.

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.

from babel-minify-webpack-plugin.

mosesoak avatar mosesoak commented on July 28, 2024

(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.)

from babel-minify-webpack-plugin.

seansd-zz avatar seansd-zz commented on July 28, 2024

Yes for me the minify of variables and what not is happening but agree that white space not getting stripped

from babel-minify-webpack-plugin.

qm3ster avatar qm3ster commented on July 28, 2024

Is there really a reason to use this strategy?
So far, I have seen that basically every rule I leave enabled improved bundle size, even without node_modules dependencies.
When would you need to optimize for compile time rather than bundle size?

from babel-minify-webpack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.