0.1.0-beta.1 • Published 5 years ago

babel-plugin-transform-runtime-project v0.1.0-beta.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

babel-plugin-transform-runtime-project

A Babel Plugin,for tranforming runtime ES5+ javascript code into ES5 in whole project, including most of the node_modules packages which don't use babel-plugin-transform-runtime to simplify codes.

Installation

npm i babel-plugin-transform-runtime-project

Use in webpack babel-loader

Add one more rules config like below

{
    test: /\.(js|jsx)?$/,
    // please especially focus on the exclude config, this tells the plugin do not transfrom these packages!!!
    // ofcourse, u can add more excluded packages if compiler effciency is required
    exclude: [
        /node_modules\/babel-/,
        /node_modules\/core-js\//,
        /node_modules\/regenerator-runtime\//,
        /node_modules\/webpack\//,
        /node_modules\/webpack-/
    ],
    use: [{
        loader: 'babel-loader',
        options: {
            presets: [
                ['env', {
                    targets: {
                        browsers: [
                            'iOS >= 8.0',
                            'Android >= 4.4',
                            'ie >= 9',
                            'Edge >= 12'
                        ]
                    },
                    debug: !isProd,
                    useBuiltIns: true
                }],
                'stage-0',
                'react'
            ],
            plugins: [
                'transfrom-runtime-project'
            ],
            cacheDirectory: true
        }
    }]
}

Technical details

  • Filter those helper function declarations which didn't be transformed by babel-plugin-transform-runtime by bable-helpers
  • Remove these function declarations in files
  • Be careful to degrate scope uid of helper functions
  • Use this.addHelper to add helpers function by refrence to bable-runtime
  • Keep all the regenerator aliasing & core-js aliasing features
0.1.0-beta.1

5 years ago