Skip to content

wvvwdev/karma-rollup-preprocessor

 
 

Repository files navigation

Karma preprocessor to bundle ES2015 modules using Rollup.

Build Status Dependency Status Downloads Version License


Features

  • Rebundles your files when watched dependencies change
  • Caches bundle output for improved performance
  • Maintained with heart by @jlmakes

Installation

npm install karma-rollup-preprocessor --save-dev

Configuration

All the options detailed in the Rollup Documentation can be passed to rollupPreprocessor.

Standard

Below is a well-founded recommendation using the Bublé ES2015 transpiler:

// karma.conf.js
module.exports = function (config) {
	config.set({

		files: [
			// Watch src files for changes but
			// don't load them into the browser.
			{ pattern: 'src/**/*.js', included: false },
			'test/**/*.spec.js',
		],

		preprocessors: {
			'src/**/*.js': ['rollup'],
			'test/**/*.spec.js': ['rollup'],
		},

		rollupPreprocessor: {
			plugins: [
				require('rollup-plugin-buble')(),
			],
			format: 'iife',               // Helps prevent naming collisions.
			moduleName: '<your_project>', // Required for 'iife' format.
			sourceMap: 'inline',          // Sensible for testing.
		},
	});
};

Configured Preprocessors

Below shows an example where configured preprocessors can be very helpful:

// karma.conf.js
module.exports = function (config) {
	config.set({

		files: [
			// Watch src files for changes but
			// don't load them into the browser.
			{ pattern: 'src/**/*.js', included: false },
			'test/**/*.spec.js',
		],

		preprocessors: {
			'test/buble/**/*.spec.js': ['rollup'],
			'test/babel/**/*.spec.js': ['rollupBabel'],
		},

		rollupPreprocessor: {
			plugins: [
				require('rollup-plugin-buble')(),
			],
			format: 'iife',
			moduleName: '<your_project>',
			sourceMap: 'inline',
		},

		customPreprocessors: {
			// Clones the base preprocessor, but overwrites
			// its options with those defined below.
			rollupBabel: {
				base: 'rollup',
				options: {
					// In this case, to use
					// a different transpiler:
					plugins: [
						require('rollup-plugin-babel')(),
					],
				}
			}
		}
	});
};

Support

Supports all Rollup plug-ins, and works on Node 4 and up. Happy bundling!

About

Karma preprocessor to bundle ES2015 modules using Rollup.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%