Preprocessor to compile ES6 on the fly with babel.
babel and karma-babel-preprocessor only convert ES6 modules to CommonJS/AMD/SystemJS/UMD. If you choose CommonJS, you still need to resolve and concatenate CommonJS modules on your own. We recommend karma-browserify + babelify or webpack + babel-loader in such cases.
npm install karma-babel-preprocessor --save-dev
npm install babel-preset-env --save-dev
See babel options for more details.
options properties are passed to babel.
In addition to the
options property, you can configure any babel options with function properties. This is useful when you want to give different babel options from file to file.
For example, inline sourcemap configuration would look like the following.
Third-party libraries may not work properly if you apply
karma-babel-preprocessor to them. It also introduces unnecessary overhead. Make sure to explicitly specify files that you want to preprocess.
Because it preprocesses files in
node_modules and may break third-party libraries like jasmine #18.
If you need polyfill, make sure to include it in
npm install babel-polyfill --save-dev
In most cases, you don't need to explicitly specify
plugins option. By default, Karma loads all sibling NPM modules which have a name starting with karma-*. If need to do so for some reason, make sure to include
'karma-babel-preprocessor' in it.
karma-babel-preprocessor supports custom preprocessor. Set
base: 'babel' in addition to normal preprocessor config.