summaryrefslogtreecommitdiff
path: root/babel.config.js
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2019-02-20 21:27:23 +0100
committerWinnie Hellmann <winnie@gitlab.com>2019-02-21 11:02:32 +0100
commitdc9a67652d77a56038d3132aab1856e555e4c769 (patch)
tree4f6723bea60aec03c3bbbb03e9306eb9603ead45 /babel.config.js
parent8d74aab4289fb7a050e0163bf1affa9e62bb079e (diff)
downloadgitlab-ce-dc9a67652d77a56038d3132aab1856e555e4c769.tar.gz
Transpile @gitlab/ui for Jest
Diffstat (limited to 'babel.config.js')
-rw-r--r--babel.config.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/babel.config.js b/babel.config.js
new file mode 100644
index 00000000000..e3de8ef2d83
--- /dev/null
+++ b/babel.config.js
@@ -0,0 +1,47 @@
+/* eslint-disable import/no-commonjs, filenames/match-regex */
+
+const BABEL_ENV = process.env.BABEL_ENV || process.env.NODE_ENV || null;
+
+const presets = [
+ [
+ '@babel/preset-env',
+ {
+ modules: false,
+ targets: {
+ ie: '11',
+ },
+ },
+ ],
+];
+
+// include stage 3 proposals
+const plugins = [
+ '@babel/plugin-syntax-dynamic-import',
+ '@babel/plugin-syntax-import-meta',
+ '@babel/plugin-proposal-class-properties',
+ '@babel/plugin-proposal-json-strings',
+ '@babel/plugin-proposal-private-methods',
+];
+
+// add code coverage tooling if necessary
+if (BABEL_ENV === 'coverage') {
+ plugins.push([
+ 'babel-plugin-istanbul',
+ {
+ exclude: ['spec/javascripts/**/*', 'app/assets/javascripts/locale/**/app.js'],
+ },
+ ]);
+}
+
+// add rewire support when running tests
+if (BABEL_ENV === 'karma' || BABEL_ENV === 'coverage') {
+ plugins.push('babel-plugin-rewire');
+}
+
+// Jest is running in node environment
+if (BABEL_ENV === 'jest') {
+ plugins.push('transform-es2015-modules-commonjs');
+ plugins.push('dynamic-import-node');
+}
+
+module.exports = { presets, plugins };