-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskfile-babel.js
53 lines (49 loc) · 1.22 KB
/
taskfile-babel.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// taskr babel plugin with Babel 7 support
// https://github.com/lukeed/taskr/pull/305
const extname = require('path').extname;
const transform = require('@babel/core').transform
const babelServerOpts = {
presets: [
'@babel/preset-typescript',
['@babel/preset-react', { useBuiltIns: true }],
[
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
node: '8.3',
},
loose: true
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties', { loose: true }],
],
}
module.exports = function (task) {
task.plugin('babel', {}, function* (
file,
) {
const babelOpts = babelServerOpts
const options = {
...babelOpts,
plugins: [
...babelOpts.plugins,
],
compact: true,
babelrc: false,
configFile: false,
filename: file.base,
sourceMaps: true,
}
const output = transform(file.data, options)
const ext = extname(file.base)
// Replace `.ts|.tsx|.jsx` with `.js` in files with an extension
if (ext) {
const extRegex = new RegExp(ext.replace('.', '\\.') + '$', 'i')
file.base = file.base.replace(extRegex, '.js')
}
file.data = Buffer.from(output.code)
})
}