-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathconfigure-jsx-transform.js
More file actions
43 lines (35 loc) · 1.2 KB
/
configure-jsx-transform.js
File metadata and controls
43 lines (35 loc) · 1.2 KB
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
const VersionChecker = require('ember-cli-version-checker');
function requireTransform(transformName) {
return require.resolve(transformName);
}
function hasPlugin(plugins, name) {
for (const maybePlugin of plugins) {
const plugin = Array.isArray(maybePlugin) ? maybePlugin[0] : maybePlugin;
const pluginName = typeof plugin === 'string' ? plugin : plugin.name;
if (pluginName === name) {
return true;
}
}
return false;
}
module.exports = function configureJsxTransform(parent) {
const options = (parent.options = parent.options || {});
const checker = new VersionChecker(parent).for('ember-cli-babel', 'npm');
options.babel = options.babel || {};
options.babel.plugins = options.babel.plugins || [];
if (checker.satisfies('^6.0.0-beta.1')) {
if (!hasPlugin(options.babel.plugins, 'babel-plugin-transform-react-jsx')) {
options.babel.plugins.push(
requireTransform('babel-plugin-transform-react-jsx')
);
}
} else if (checker.gte('7.0.0')) {
if (
!hasPlugin(options.babel.plugins, '@babel/plugin-transform-react-jsx')
) {
options.babel.plugins.push(
requireTransform('@babel/plugin-transform-react-jsx')
);
}
}
};