This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
.babelrc.js
66 lines (65 loc) · 2.43 KB
/
.babelrc.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
const { join } = require(`path`) // eslint-disable-line
const ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || (process.env.NODE_ENV = `development`)
const envDev = ENV === `development`
const envProd = ENV === `production`
const envTest = ENV === `test`
const rootDir = join(__dirname, ``)
const srcDir = join(__dirname, `src`)
const pubDir = join(__dirname, `public`)
module.exports = {
sourceMaps: envTest ? `inline` : false,
plugins: [
envTest ? `babel-plugin-istanbul` : null,
[`babel-plugin-react-css-modules`, {
context: rootDir,
exclude: `node_modules`,
filetypes: { ".scss": { syntax: `postcss-scss` } },
generateScopedName: `[local]_[hash:base64:5]`,
webpackHotModuleReloading: envDev
}],
[`babel-plugin-provide-modules`, {
"core-js/fn/promise": `Promise`,
"preact": [`h`],
"react": [`Component`, `React`],
"regenerator-runtime": `regeneratorRuntime`,
"prop-types": `PropTypes`
}],
envTest ? ["module-resolver", {
"root": ["./src"],
"alias": {
// Application Aliases
'@': srcDir,
'@components': join(srcDir, `app/components`),
'@models': join(srcDir, `app/models`),
'@public': pubDir,
'@routes': join(srcDir, `app/routes`),
'@services': join(srcDir, `app/services`),
// Module Aliases
'react': `preact-compat-enzyme`,
'react-dom': `preact-compat-enzyme`,
'create-react-class': `preact-compat/lib/create-react-class`,
'react-dom/server': `preact-render-to-string`,
'react-dom/test-utils': `preact-test-utils`,
'react-test-renderer/shallow': `preact-test-utils`,
'react-test-renderer': `preact-test-utils`,
'react-addons-test-utils': `preact-test-utils`,
'react-addons-transition-group': `preact-transition-group`
}
}] : null,
[`babel-plugin-webpack-alias`, { config: `./webpack.config.js` }],
[`inline-replace-variables`, {
ENV: { type: `node`, replacement: `process.env.NODE_ENV` }
}],
[`@babel/plugin-transform-react-jsx`, { pragma: `h` }],
envProd ? [`@babel/transform-runtime`, {
helpers: false,
polyfill: false,
regenerator: true
}] : null
].filter(nonNull => nonNull),
presets: [
[`@babel/preset-env`, { modules: envTest && `commonjs`, useBuiltIns: `usage` }],
`@babel/preset-stage-0`,
`@babel/preset-flow`
].filter(nonNull => nonNull)
}