-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tell user what browser support their application was built with (#3782)
* Warn about browsers during build * Better message
- Loading branch information
Showing
6 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters