Using the whitelist option with Babel external helpers

I am trying to use Rollup with Babel external-helpers. It works, but it throws a bunch of assistant babels that I don't even need, like asyncGenerator.

The docs show a whitelisted option , but I can't get it to work

rollup.rollup({
    entry: 'src/buttonDropdown.es6',
    plugins: [
        babel({
            presets: ['react', ['es2015', { modules: false }], 'stage-2'],
            plugins: [['external-helpers', { whitelist: ['asyncGenerator'] }]]
        })
    ]
})

The above has no effect: all of Babel’s helpers still fall into my resulting package.

What is the correct way to use this function, and is there a complete list of handler names that the white array accepts?

Or there’s another Rollup plugin that I have to use with Rollup to automatically “tremble” the babel’s external helpers.

+4
2

babel-plugin-external-helpers . , , - , . :

classCallCheck(this, Foo);
// or
babelHelpers.classCallCheck(this, Foo);

, rollup-plugin-babel babelHelpers .

, whitelist external-helpers. babel-external-helpers, babelHelpers.

rollup-plugin-babel, babelHelpers. , . babel-external-helpers whitelist. . .

, rollup . (, asyncGenerator) , , - , .

I rollup-plugin-babel PR, whitelist babelHelpers . :

require("rollup").rollup({
  entry: "./src/main.js",
  plugins: [
    require("rollup-plugin-babel")({
      "presets": [["es2015", { "modules": false }]],
      "plugins": ["external-helpers"],
      "externalHelpersWhitelist": ['classCallCheck', 'inherits', 'possibleConstructorReturn']
    })
  ]
}).then(bundle => {
  var result = bundle.generate({
    format: 'iife'
  });
  require("fs").writeFileSync("./dist/bundle.js", result.code);
}).then(null, err => console.error(err));

, npm, git rollup -c.

, - , , . github .

+6

issue GitHub.

Babel Hzoo ,

, - , .

, . Krucher,

  • - forking

    "babel": {
    "presets": [
      "es2015"
    ],
    "disablePlugins": [
        "babel-plugin-transform-es2015-modules-commonjs"
    ]
    

    }

es2015-with-commonjs, . define your own preset extend .

  • tree-shaking, , Dr. . webpack2 Babel6. , .

    • -, ES6 single bundle file. , , .
    • -, minified, dead code. , , , . ( ).

.

.

  • .

aplugin

babel-plugin-transforn-runtime - , bundle external dependancy, , side-effects.

rollup.js,

,

, babylon

- async-functions (since babylon 6.9.1)
- exponentiation-operator (since babylon 6.9.1)
- trailing-function-commas (since babylon 6.9.1)**

loganfsmyth thread.

" ", , .

, , , , .

:

-

" --external-helpers . Babels, babel-plugin-transform-runtime, babel-runtime (, , polyfill)."

, .

, .

+1

Source: https://habr.com/ru/post/1657618/


All Articles