forked from jackmellis/require-extension-hooks-babel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (27 loc) · 791 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const babel = require('@babel/core');
const defaultConfig = {
exclude : [/node_modules|coverage/],
presets : [
['env', {
targets : {
node : 'current'
}
}]
],
sourceMaps : true
};
let globalConfig = Object.assign({}, defaultConfig);
module.exports = function({content, filename}){
for (let x = 0, l = globalConfig.exclude.length; x < l; x++){
if (filename.match(globalConfig.exclude[x])){
return;
}
}
let config = Object.assign({ filename, sourceFileName : filename }, globalConfig);
delete config.exclude;
let result = babel.transform(content, config);
return { content : result.code, sourceMap : result.map };
};
module.exports.configure = function (options) {
globalConfig = Object.assign({}, defaultConfig, options);
};