forked from magento/pwa-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.config.js
96 lines (93 loc) · 3.58 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const browsers = require('./browserslist');
const plugins = [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-object-rest-spread'],
['@babel/plugin-syntax-dynamic-import'],
['@babel/plugin-syntax-jsx'],
['@babel/plugin-transform-react-jsx'],
['babel-plugin-graphql-tag']
];
const targets = {
dev: 'last 2 Chrome versions',
prod: browsers,
test: 'node 10'
};
const config = api => {
const envConfigs = {
/**
* Watch mode and build:esm partial transpilation mode.
* The module-resolver plugin makes Babel recognize import paths from
* package root, like 'src/classify'.
*
* BUT VENIA SHOULD NOT USE THEM, because it makes Venia less portable
* and Venia should be more portable than an average PWA Studio app.
*/
development: {
// Ignore everything with underscores except stories
ignore: [/\/__(tests?|mocks|fixtures|helpers|dist)__\//],
plugins: [
...plugins,
[
'module-resolver',
{
root: ['./'],
/**
* Exported modules will be consumed by other projects
* which import Venia. Those projects will need to
* override the 'src/drivers' dependency so Venia
* modules will run outside the Venia app. This alias
* exports the modules so the drivers dependency is
* a unique string '@magento/venia-drivers', which is
* less likely to collide with an existing dependency
* than 'src/drivers' is.
*
* In webpack (or any build system) config for a project
* using Venia modules, you must write an override for
* '@magento/venia-drivers' and make an alias to that
* module in your build configuration, e.g.:
*
* alias: {
* '@magento/venia-drivers': './src/veniaDrivers'
* }
*
* to map from this virtual string to your replacement.
*/
alias: {
'^src/drivers$': '@magento/venia-drivers'
},
/**
* Suppress console warning about missing dependencies.
*/
loglevel: 'silent'
}
]
],
presets: [
['@babel/preset-env', { modules: false, targets: targets.dev }]
]
},
production: {
plugins: [
...plugins,
[
'@babel/plugin-transform-runtime',
{ helpers: true, regenerator: true }
]
],
presets: [
['@babel/preset-env', { modules: false, targets: targets.prod }]
]
},
test: {
plugins: [...plugins, ['babel-plugin-dynamic-import-node']],
presets: [
[
'@babel/preset-env',
{ modules: 'commonjs', targets: targets.test }
]
]
}
};
return envConfigs[api.env() || 'development'];
};
module.exports = config;