forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
babel.config.js
77 lines (72 loc) · 2.56 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// @ts-check
const path = require('path')
const semver = require('semver')
const logger = require('signale')
/** @type {import('@babel/core').ConfigFunction} */
module.exports = api => {
const isTest = api.env('test')
api.cache.forever()
/**
* Whether to instrument files with istanbul for code coverage.
* This is needed for e2e test coverage.
*/
const instrument = Boolean(process.env.COVERAGE_INSTRUMENT && JSON.parse(process.env.COVERAGE_INSTRUMENT))
if (instrument) {
logger.info('Instrumenting code for coverage tracking')
}
return {
presets: [
// Can't put this in plugins because it needs to run as the last plugin.
...(instrument ? [{ plugins: [['babel-plugin-istanbul', { cwd: path.resolve(__dirname) }]] }] : []),
[
'@babel/preset-env',
{
// Node (used for testing) doesn't support modules, so compile to CommonJS for testing.
modules: isTest ? 'commonjs' : false,
bugfixes: true,
useBuiltIns: 'entry',
include: [
// Polyfill URL because Chrome and Firefox are not spec-compliant
// Hostnames of URIs with custom schemes (e.g. git) are not parsed out
'web.url',
// URLSearchParams.prototype.keys() is not iterable in Firefox
'web.url-search-params',
// Commonly needed by extensions (used by vscode-jsonrpc)
'web.immediate',
// Always define Symbol.observable before libraries are loaded, ensuring interopability between different libraries.
'esnext.symbol.observable',
],
// See https://github.com/zloirock/core-js#babelpreset-env
corejs: semver.minVersion(require('./package.json').dependencies['core-js']),
},
],
'@babel/preset-typescript',
[
'@babel/preset-react',
{
runtime: 'automatic',
},
],
],
plugins: [
['@babel/plugin-transform-typescript', { isTSX: true }],
'babel-plugin-lodash',
[
'webpack-chunkname',
{
/**
* Autogenerate `webpackChunkName` for dynamic imports.
*
* import('./pages/Home') -> import(/* webpackChunkName: 'sg_pages_Home' *\/'./pages/Home')
*/
getChunkName: (/** @type string */ importPath) => {
const chunkName = importPath
.replace(/[./]+/g, '_') // replace "." and "/" with "_".
.replace(/(^_+)/g, '') // remove all leading "_".
return `sg_${chunkName}`
},
},
],
],
}
}