karma-rollup-preprocessor
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -30,9 +30,11 @@ // Karma configuration | ||
rollupPreprocessor: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
rollup: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
} | ||
}, | ||
@@ -39,0 +41,0 @@ |
@@ -14,2 +14,4 @@ 'use strict'; | ||
var rollupConfig = config.rollup || {}; | ||
var bundleConfig = config.bundle || {}; | ||
@@ -21,9 +23,20 @@ function preprocess (content, file, done) | ||
try { | ||
config.entry = file.originalPath; | ||
rollupConfig.entry = file.originalPath; | ||
rollup | ||
.rollup(config) | ||
.rollup(rollupConfig) | ||
.then(function (bundle) | ||
{ | ||
var processed = bundle.generate({format: 'es6'}).code; | ||
if (!bundleConfig.hasOwnProperty('format')) { | ||
bundleConfig.format = 'es6'; | ||
} | ||
var generated = bundle.generate(bundleConfig); | ||
var processed = generated.code; | ||
if (bundleConfig.sourceMap === 'inline') { | ||
var url = generated.map.toUrl(); | ||
processed += "\n" + '//# sourceMappingURL=' + url; | ||
} | ||
done(null, processed); | ||
@@ -30,0 +43,0 @@ }) |
{ | ||
"name": "karma-rollup-preprocessor", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "A rollup preprocessor for Karma", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,1 +1,3 @@ | ||
# karma-rollup-preprocessor | ||
[![Build Status](https://travis-ci.org/showpad/karma-rollup-preprocessor.svg)](https://travis-ci.org/showpad/karma-rollup-preprocessor) | ||
@@ -5,7 +7,2 @@ [![npm version](https://img.shields.io/npm/v/karma-rollup-preprocessor.svg)](https://www.npmjs.org/package/karma-rollup-preprocessor) | ||
# karma-rollup-preprocessor | ||
> Preprocessor to bundle ES6 modules fly with [rollup](http://rollupjs.org/). | ||
@@ -17,10 +14,19 @@ | ||
# Installation | ||
```bash | ||
npm install karma-rollup-preprocessor --save-dev | ||
``` | ||
# Configuration | ||
The `rollupPreprocessor` configuration is optional. (You'll need to install more dependencies). It takes two keys: `rollup` and | ||
`bundle`. | ||
See [rollup wiki](https://github.com/rollup/rollup/wiki) for more details | ||
The `rollupPreprocessor` configuration is optional. (You'll need to install more dependencies) | ||
`rollup` is the configuration object for `rollup` (See [rollup.rollup](https://github.com/rollup/rollup/wiki/JavaScript-API#rolluprollup-options-) for more details). | ||
`bundle` is the configuration object used when generating the bundle (See [bundle.generate](https://github.com/rollup/rollup/wiki/JavaScript-API#bundlegenerate-options-) for more details) | ||
*Notice* this is preprocessor and does not write a file or return the bundle, only the content of the processed file gets changed. | ||
So when adding the `sourceMaps` options, `inline` is the only logical value. | ||
## Example | ||
```js | ||
@@ -33,11 +39,17 @@ module.exports = function (config) { | ||
rollupPreprocessor: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
rollup: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
}, | ||
bundle: { | ||
sourceMap: 'inline' | ||
} | ||
} | ||
}); | ||
}; | ||
}; | ||
``` |
8494
10
120
53