faucet-pipeline-js
Version:
JavaScript module bundling for faucet-pipeline
50 lines (42 loc) • 1.23 kB
JavaScript
;
let { loadExtension } = require("faucet-pipeline-core/lib/util");
module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browsers }) {
let settings = {};
let plugins = [];
let extensions = [];
if(exclude) {
settings.exclude = exclude.map(pkg => {
// distinguish paths from package identifiers - as per Node's
// resolution algorithm <https://nodejs.org/api/modules.html>, a
// string is a path if it begins with `/`, `./` or `../`
// FIXME: duplicates faucet-core's `resolvePath`, resulting in
// inconsistency WRT working directory
return /^\.{0,2}\//.test(pkg) ? pkg : `node_modules/${pkg}/**`;
});
}
if(esnext) {
settings.presets = [
["@babel/preset-env", {
modules: false,
targets: {
browsers: browsers || []
}
}]
];
}
if(jsx) {
extensions.push(".jsx");
let { pragma } = jsx;
let options = pragma ? { pragma } : {};
plugins.push(["@babel/plugin-transform-react-jsx", options]);
}
if(plugins.length) {
settings.plugins = plugins;
}
let babel = loadExtension("rollup-plugin-babel",
"failed to activate ESNext transpiler", "faucet-pipeline-esnext");
return {
plugin: babel(settings),
extensions
};
};