forked from preactjs/preact-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.js
38 lines (32 loc) · 1.18 KB
/
babel.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
var isProd = (process.env.BABEL_ENV || process.env.NODE_ENV) === "production";
/**
* test env detection is used to default mode for
* preset-env modules to "commonjs" otherwise, testing framework
* will struggle
*/
var isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === "test";
// default supported browser.
var defaultBrowserList = ["> 1%", "last 2 versions", "IE >= 9"];
// preact-cli babel configs
var babelConfigs = require("./lib/lib/babel-config").default;
/**
* preset as a function means allow users to override some options
* like env, modules for environment
*/
module.exports = function preactCli(ctx, userOptions = {}) {
// set default configs based on user environment
var presetOptions = {
env: isProd ? "production" : "development",
modules: isTest ? "commonjs" : false,
browsers: defaultBrowserList
};
// user specified options always the strongest
Object.keys(presetOptions).forEach(function (key) {
presetOptions[key] = userOptions[key] || presetOptions[key];
});
// yay! return the configs
return babelConfigs(
{ env: { production: presetOptions.env === "production" } },
{ modules: presetOptions.modules, browsers: presetOptions.browsers }
);
};