-
Notifications
You must be signed in to change notification settings - Fork 24.4k
/
main.js
106 lines (97 loc) · 3.01 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
*/
'use strict';
var resolvePlugins = require('../lib/resolvePlugins');
const getPreset = (src, options) => {
const plugins = [];
const isNull = src === null || src === undefined;
const hasClass = isNull || src.indexOf('class') !== -1;
const hasForOf =
isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1);
plugins.push(
'syntax-class-properties',
'syntax-trailing-function-commas',
'transform-class-properties',
'transform-es2015-block-scoping',
'transform-es2015-computed-properties',
'transform-es2015-destructuring',
'transform-es2015-function-name',
'transform-es2015-literals',
'transform-es2015-parameters',
'transform-es2015-shorthand-properties',
'transform-flow-strip-types',
'transform-react-jsx',
'transform-regenerator',
require('../transforms/transform-regenerator-runtime-insertion'),
[
'transform-es2015-modules-commonjs',
{strict: false, allowTopLevelThis: true},
],
);
if (isNull || src.indexOf('async') !== -1 || src.indexOf('await') !== -1) {
plugins.push('syntax-async-functions');
}
if (hasClass) {
plugins.push('transform-es2015-classes');
}
if (isNull || src.indexOf('=>') !== -1) {
plugins.push('transform-es2015-arrow-functions');
}
if (isNull || src.indexOf('const') !== -1) {
plugins.push('check-es2015-constants');
}
if (isNull || hasClass || src.indexOf('...') !== -1) {
plugins.push('transform-es2015-spread');
plugins.push('transform-object-rest-spread');
}
if (isNull || src.indexOf('`') !== -1) {
plugins.push('transform-es2015-template-literals');
}
if (isNull || src.indexOf('Object.assign') !== -1) {
plugins.push('transform-object-assign');
}
if (hasForOf) {
plugins.push(['transform-es2015-for-of', {loose: true}]);
}
if (hasForOf || src.indexOf('Symbol') !== -1) {
plugins.push(require('../transforms/transform-symbol-member'));
}
if (
isNull ||
src.indexOf('React.createClass') !== -1 ||
src.indexOf('createReactClass') !== -1
) {
plugins.push('transform-react-display-name');
}
if (isNull || src.indexOf('import(')) {
plugins.push(require('../transforms/transform-dynamic-import'));
}
if (options && options.dev) {
plugins.push('transform-react-jsx-source');
}
return {
comments: false,
compact: true,
plugins: resolvePlugins(plugins),
};
};
const base = getPreset(null);
const devTools = getPreset(null, {dev: true});
module.exports = options => {
if (options.withDevTools == null) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!env || env === 'development') {
return devTools;
}
}
return base;
};
module.exports.getPreset = getPreset;