forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
63 lines (57 loc) · 1.65 KB
/
babel.config.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
// This file is part of Indico.
// Copyright (C) 2002 - 2024 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.
/* eslint-env commonjs */
/* eslint-disable import/unambiguous, import/no-commonjs */
const path = require('path');
const process = require('process');
const plugins = [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
'lodash',
[
'@dr.pogodin/react-css-modules',
{
exclude: 'node_modules',
context: 'indico/modules',
filetypes: {
'.scss': {
syntax: 'postcss-scss',
},
},
autoResolveMultipleImports: true,
generateScopedName: '[path]___[name]__[local]___[hash:base64:5]',
},
],
'macros',
];
if (process.env.NODE_ENV === 'test') {
plugins.push(['flask-urls', {importPrefix: 'indico-url', mock: true}]);
} else {
// if there is a valid build config, we can use it to generate proper URLs
try {
const config = require(process.env.INDICO_PLUGIN_ROOT
? path.join(process.env.INDICO_PLUGIN_ROOT, 'webpack-build-config')
: './webpack-build-config');
const globalBuildConfig = config.indico ? config.indico.build : config.build;
plugins.push([
'flask-urls',
{
importPrefix: 'indico-url',
urlMap: require(config.build.urlMapPath).rules,
basePath: globalBuildConfig.baseURLPath,
},
]);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}
}
module.exports = {
presets: ['@babel/preset-env', '@babel/react', '@babel/preset-typescript'],
plugins,
};