UNPKG

1.62 kBJavaScriptView Raw
1const utils = require('./cli/utils');
2
3/* What variables does this config depend on?
4 * process.env.BABEL_EXTENSION_PATH -- a resolved path
5 * api.env -- this is process.env.BABEL_ENV if it exists (it should)
6 * process.env.BABEL_INCLUDE_TIMING_FUNCTIONS
7 */
8
9module.exports = function babelConfig(api) {
10 utils.verbose(`Generating Babel Config`);
11 const presets = [
12 "@babel/env",
13 "@babel/preset-react"
14 ];
15 const plugins = [
16 ["@babel/plugin-proposal-decorators", { legacy: true }],
17 "@babel/plugin-proposal-class-properties",
18 "babel-plugin-styled-components",
19 "babel-plugin-syntax-dynamic-import"
20 ];
21 if (api.env("development")) {
22 if (process.env.BABEL_EXTENSION_PATH && !process.env.BABEL_EXTENSION_PATH.includes(__dirname)) {
23 utils.verbose("Not using react-hot-loader/babel plugin with auspice extensions as this produces an error. TO FIX.");
24 /* with extensions from a dir not within the main auspice directory we get the error:
25 * Module not found: Error: Can't resolve 'react-hot-loader' in ...extension directory...
26 * Which I can't fix. Tried:
27 * require.resolve("react-hot-loader/babel")
28 * setting babelrcRoots
29 * but google seems to have failed me.
30 * It may be a bug with "react-hot-loader/babel" as the other plugins work just fine!
31 */
32 } else {
33 plugins.push("react-hot-loader/babel");
34 }
35 }
36 if (process.env.BABEL_INCLUDE_TIMING_FUNCTIONS === "false") {
37 plugins.push(["strip-function-call", {strip: ["timerStart", "timerEnd"]}]);
38 }
39 api.cache(true);
40 return {
41 presets,
42 plugins
43 };
44};