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
MIT License
702 stars 87 forks source link

Rollup build works in Development fails In Production Environment #103

Closed kennetpostigo closed 7 years ago

kennetpostigo commented 7 years ago

I'm working on a library that utilizes async/await feature with babel. When I was working on the library I noticed when I setup the production settings for the output that the development environment works great, but as soon as I switch to production it fails. I've tried lost of different transform combinations to try to get it working switching from transform-async-to-generator to async-to-promises but to no avail. I'm not sure but I think it could be something I may be doing wrong with runtimeHelpers, the reason why I turn them on is because If they are not included I get an error when the library is required in an application saying the regeneratorRuntime is undefined.

Here is my .babelrc:

{
  "env": {
    "development": {
      "presets": [
        "es2015-rollup",
        "es2017",
        "stage-1"
      ],
      "plugins": [
        ["transform-runtime", {
        "polyfill": true,
        "regenerator": true
        }],
      ]
    },
    "production": {
      "presets": [
        "es2015-rollup",
        "es2017",
        "stage-1",
        "babili"
      ],
      "plugins": [
        ["transform-runtime", {
        "polyfill": false,
        "regenerator": true
        }],
      ],
      "comments": false,
      "minified": true,
      "compact": true
    }
}

Here is my is the rollup.config.js:

import babel from 'rollup-plugin-babel';

var dest = 'dist/greed.js';
var destES = 'dist/greed.es.js';

if (process.env.NODE_ENV === 'production') {
    dest = 'dist/greed.min.js';
    destES = 'dist/greed.min.es.js';
}

export default {
    entry: 'src/greed.js',
    moduleName: 'Greed',
    targets: [
        { dest: dest, format: 'umd' },
        { dest: destES, format: 'es' },
    ],
    plugins: [
        babel({
            babelrc: true,
            runtimeHelpers: true,
            exclude: 'node_modules/**',
        })
    ],
    external: [
                'whatwg-fetch',
        'babel-runtime/regenerator',
        'babel-runtime/core-js/json/stringify',
        'babel-runtime/helpers/asyncToGenerator'
    ],
    globals: {
                'whatwg-fetch': 'whatwg-fetch',
        'babel-runtime/regenerator':'babel-runtime/regenerator',
        'babel-runtime/core-js/json/stringify':'babel-runtime/core-js/json/stringify',
        'babel-runtime/helpers/asyncToGenerator':'babel-runtime/helpers/asyncToGenerator'
    }
};

The error message:

Error transforming /Users/kennetpostigo/Projects/greed/packages/greed/src/greed.js with 'babel' plugin: An unexpected situation arose. Please raise an issue at https://github.com/rollup/rollup-plugin-babel/issues. Thanks!
Error: Error transforming /Users/kennetpostigo/Projects/greed/packages/greed/src/greed.js with 'babel' plugin: An unexpected situation arose. Please raise an issue at https://github.com/rollup/rollup-plugin-babel/issues. Thanks!
    at preflightCheck (/Users/kennetpostigo/Projects/greed/packages/greed/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:50:10)
    at Object.transform$1 [as transform] (/Users/kennetpostigo/Projects/greed/packages/greed/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:104:18)
    at /Users/kennetpostigo/Projects/greed/packages/greed/node_modules/rollup/src/utils/transform.js:19:35
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:609:11)
    at run (bootstrap_node.js:382:7)
    at startup (bootstrap_node.js:137:9)
    at bootstrap_node.js:497:3
kennetpostigo commented 7 years ago

The only difference that seems to make the output fail is babili. Is this a known issue?