rollup / rollup-plugin-babel

This package has moved and is now available at @rollup/plugin-babel / https://github.com/rollup/plugins/tree/master/packages/babel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uses babel.config.js when babelrc is false

dfrankland opened this issue · comments

It has taken me a long while to figure out that the problems I was having with rollup-plugin-babel were because there is a conflict between the settings passed with babelrc: false and the actual babel.config.js.

Is it possible to disable using babel.config.js when bablerc is set to false?

Even if I set runtimeHelpers: true this causes code to compile weirdly. I am using preserveModules with Rollup and when passing runtimeHelpers: true it causes node_modules to be placed in the output directory with @babel/runtime as the only dependency in that folder.

The only way around this is to set plugins only meant for babel.config.js and not Rollup within an env block.

This problem will likely be alleviated when #325 lands, but will still be hard to debug / figure out the proper way of configuring when someone has this problem.

Example

rollup.config.js

...
babel({
  extensions: ['.js', '.ts'],
  exclude: 'node_modules/**',
  babelrc: false,
  // This fixes the problem:
  //
  // configFile: false,
  sourceMaps: true,
  presets: [
    [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
    '@babel/preset-typescript',
  ],
})
...

babel.config.js

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
    '@babel/preset-typescript',
  ],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-transform-runtime', // Makes `rollup-plugin-babel` complain
  ],

  // Workaround:
  //
  // env: {
  //   test: {
  //     plugins: ['@babel/plugin-transform-runtime'],
  //   },
  // },
};

Seems like there's another option configFile which must be passed in as false along with babelrc to completely disable loading configurations outside of the Rollup config. It might be a good idea to document this and maybe even throw some errors if only one or the other is passed.

Feel free to prepare a documentation PR, as to throwing errors - that's not a good idea, because rollup-plugin-babel should reflect closely Babel's options and if Babel has 2 separate flags for this, then the same should be handled by this plugin.

Sure, can do. Sorry, errors might be too harsh, more like warnings, but I get your point 👍

Going to close this now, because I'm cleaning the issues to migrate this plugin to Rollup plugins monorepo ( https://github.com/rollup/plugins ). Once that happens - this can be raised once again there. Hope you understand.