Commit a4306c5d authored by Arve Knudsen's avatar Arve Knudsen Committed by Renée Kooi
Browse files

Add option babelifyDeps (#422)

parent 593eb8f3
......@@ -306,7 +306,7 @@ includes IE11. And if you have different opinions on which browsers to use,
Bankai respects `.babelrc` and [`.browserslistrc`](https://github.com/ai/browserslist) files.
Some newer JavaScript features require loading an extra library; `async/await`
being the clearest example. To enable this features, the `babel-polyfill`
being the clearest example. To enable such features, the `babel-polyfill`
library needs to be included in your application's root (e.g. `index.js`).
```js
......@@ -333,6 +333,7 @@ argument. The following options are available:
if you have your own logging system.
- __opts.watch:__ Defaults to `true`. Watch for changes in the source files and
rebuild. Set to `false` to get optimized bundles.
- __babelifyDeps:__ Defaults to true. Transform dependencies with babelify.
### `compiler.documents(routename, [opts], done(err, { buffer, hash }))`
Output an HTML bundle for a route. Routes are determined based on the project's
......
......@@ -106,6 +106,7 @@ function Bankai (entry, opts) {
this.graph.start({
dirname: this.dirname,
watch: opts.watch !== false,
babelifyDeps: opts.babelifyDeps !== false,
fullPaths: opts.fullPaths,
reload: Boolean(opts.reload),
log: this.log,
......
......@@ -64,12 +64,14 @@ function node (state, createEdge) {
b.ignore('sheetify/insert')
b.transform(sheetify)
b.transform(glslify)
// Dependencies should be transformed, but their .babelrc should be ignored.
b.transform(tfilter(babelify, { include: /node_modules/ }), {
global: true,
babelrc: false,
presets: babelPresets
})
if (state.metadata.babelifyDeps) {
// Dependencies should be transformed, but their .babelrc should be ignored.
b.transform(tfilter(babelify, { include: /node_modules/ }), {
global: true,
babelrc: false,
presets: babelPresets
})
}
// In our own code, .babelrc files should be used.
b.transform(tfilter(babelify, { exclude: /node_modules/ }), {
global: true,
......
......@@ -90,6 +90,7 @@
"rimraf": "^2.6.2",
"standard": "^11.0",
"tachyons": "^4.9.1",
"tape": "^4.8.0"
"tape": "^4.8.0",
"tmp": "0.0.33"
}
}
......@@ -5,6 +5,7 @@ var path = require('path')
var tape = require('tape')
var fs = require('fs')
var os = require('os')
var tmp = require('tmp')
var bankai = require('../')
......@@ -128,6 +129,41 @@ tape('use custom babel config for local files, but not for dependencies', functi
})
})
tape('skip babel for dependencies if babelifyDeps is false', function (assert) {
assert.plan(4)
var file = dedent`
const depFunc = require('mydep').depFunc
depFunc(1)
`
var depFile = dedent`
const depFunc = (arg) => {
console.log(arg)
}
module.exports = {
depFunc
}
`
var filename = 'js-pipeline-' + (Math.random() * 1e4).toFixed() + '.js'
const outputDir = tmp.dirSync({unsafeCleanup: true})
var tmpFilename = path.join(outputDir.name, filename)
fs.writeFileSync(tmpFilename, file)
const nodeModulesDir = path.join(outputDir.name, 'node_modules')
mkdirp.sync(nodeModulesDir)
fs.writeFileSync(path.join(nodeModulesDir, 'mydep.js'), depFile)
var compiler = bankai(tmpFilename, { watch: false, babelifyDeps: false })
compiler.scripts('bundle.js', function (err, node) {
assert.error(err, 'no error writing script')
assert.ok(node, 'output exists')
assert.ok(node.buffer, 'output buffer exists')
const compiledJs = node.buffer.toString('utf8')
assert.notOk(/['"]use strict['"]/.test(compiledJs))
outputDir.removeCallback()
})
})
tape('use custom browserslist config', function (assert) {
assert.plan(5)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment