matt3224 matt3224 - 26 days ago 13
Javascript Question

How can I tell Babel to ignore an es6 import when using the Rollup Babel plugin?

Is there any way for me to tell babel to ignore certain imports, for example i don't want babel to touch any es5 imports like polyfills.

I have tried the exclude option but it doesn't do anything. Here are my dev dependancies:


"devDependencies": {
"babel-preset-es2015-rollup": "^1.2.0",
"rollup": "^0.36.3",
"rollup-plugin-babel": "^2.6.1"
}


Also here is my index.js with comments showing what I want babel to ignore:


/* BABEL DON"T TOUCH THESE PLEASE */
import "parties/promise.js";
import "parties/fetch.js";
import "parties/domtastic.min.js";
/* END BABEL NO TOUCHY */



/* BABEL TRANSPILE THESE */
import "settings/global.js";
import "settings/tabs.js";
import "modules/helpers.js";
import "modules/modal.js";
import "modules/notify.js";
import "modules/tabs.js";
/* END BABEL TRANSPILE */


How can I do this? Do I need another package to deal with this?

Any help much appreciated, thanks.

Answer

Just use the exclude setting of the babel plugin:

// rollup.config.js
import babel from 'rollup-plugin-babel';

export default {
  // ...
  plugins: [
    babel({
      exclude: [ 'node_modules/**', 'src/parties/**' ]
    })
  ]
};