Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !3782
Something went wrong while fetching comments. Please try again.

Tell user what browser support their application was built with

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Timer/warn-browsers into next 7 years ago
  • Overview 2
  • Commits 2
  • Pipelines 0
  • Changes 6

Created by: Timer

This PR warns about specifying browsers with a method other than package.json after build.

This PR also prevents build/start when no browsers are specified.

TODO:

  • provide a link to docs about specifying browsers
  • interactive prompt (Y/n) to set defaults in package.json (?)

Fixes #3779 (closed)

Compare
  • next (base)

and
  • latest version
    d4e3bc9f
    2 commits, 2 years ago

6 files
+ 68
- 1

    Preferences

    File browser
    Compare changes
pack‎ages‎
react-d‎ev-utils‎
browsers‎Helper.js‎ +44 -0
packag‎e.json‎ +3 -1
react-‎scripts‎
con‎fig‎
path‎s.js‎ +1 -0
scr‎ipts‎
buil‎d.js‎ +9 -0
star‎t.js‎ +7 -0
packag‎e.json‎ +4 -0
packages/react-dev-utils/browsersHelper.js 0 → 100644
+ 44
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE

/**
* 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 };
packages/react-dev-utils/browsersHelper.js 0 → 100644
+ 44
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE

/**
* 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 };
packages/react-dev-utils/package.json
+ 3
- 1
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE


@@ -11,6 +11,7 @@
"node": ">=6"
},
"files": [
"browsersHelper.js",
"checkRequiredFiles.js",
"clearConsole.js",
"crashOverlay.js",
@@ -36,8 +37,9 @@
"webpackHotDevClient.js"
],
"dependencies": {
"address": "1.0.3",
"@babel/code-frame": "7.0.0-beta.37",
"address": "1.0.3",
"browserslist": "2.11.1",
"chalk": "2.3.0",
"cross-spawn": "5.1.0",
"detect-port-alt": "1.1.5",
packages/react-scripts/config/paths.js
+ 1
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE


@@ -49,6 +49,7 @@ function getServedPath(appPackageJson) {
// config after eject: we're in ./config/
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
packages/react-scripts/scripts/build.js
+ 9
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE


@@ -40,6 +40,14 @@ const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
const printBuildError = require('react-dev-utils/printBuildError');
const { printBrowsers } = require('react-dev-utils/browsersHelper');
// @remove-on-eject-begin
// Require browsers to be specified before you eject
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
if (!checkBrowsers(paths.appPath)) {
process.exit(1);
}
// @remove-on-eject-end
const measureFileSizesBeforeBuild =
FileSizeReporter.measureFileSizesBeforeBuild;
@@ -107,6 +115,7 @@ measureFileSizesBeforeBuild(paths.appBuild)
buildFolder,
useYarn
);
printBrowsers(paths.appPath);
},
err => {
console.log(chalk.red('Failed to compile.\n'));
packages/react-scripts/scripts/start.js
+ 7
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE


@@ -48,6 +48,13 @@ const createDevServerConfig = require('../config/webpackDevServer.config');
const useYarn = fs.existsSync(paths.yarnLockFile);
const isInteractive = process.stdout.isTTY;
// @remove-on-eject-begin
// Require browsers to be specified before you eject
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
if (!checkBrowsers(paths.appPath)) {
process.exit(1);
}
// @remove-on-eject-end
// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
packages/react-scripts/package.json
+ 4
- 0
  • View file @ d4e3bc9f

  • Edit in single-file editor

  • Open in Web IDE


@@ -68,5 +68,9 @@
},
"optionalDependencies": {
"fsevents": "1.1.2"
},
"browserslist": {
"development": "last 2 chrome versions",
"production": [">1%", "last 4 versions", "Firefox ESR", "not ie < 11"]
}
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
CLA Signed tag: enhancement
2
CLA Signed tag: enhancement
    Assign labels
  • Manage project labels

Milestone
2.0
2.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: facebook/create-react-app!3782
Source branch: github/fork/Timer/warn-browsers

Menu

Explore Projects Groups Snippets