forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowsersHelper.js
44 lines (39 loc) · 1.11 KB
/
browsersHelper.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
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const browserslist = require('browserslist');
const chalk = require('chalk');
const os = require('os');
function checkBrowsers(dir) {
const found = browserslist.findConfig(dir);
if (found == null) {
console.log(
chalk.red('As of react-scripts >=2 you must specify targeted browsers.') +
os.EOL +
`Please add a ${chalk.underline(
'browserslist'
)} key to your ${chalk.bold('package.json')}.`
);
return null;
}
return found;
}
function printBrowsers(dir) {
let browsers = checkBrowsers(dir);
if (browsers == null) {
console.log('Built the bundle with default browser support.');
return;
}
browsers = browsers[process.env.NODE_ENV] || browsers;
if (Array.isArray(browsers)) {
browsers = browsers.join(', ');
}
console.log(
`Built the bundle with browser support for ${chalk.cyan(browsers)}.`
);
}
module.exports = { checkBrowsers, printBrowsers };