From a3e55ee82e4172b2ff89883f88099ef34de9a3dc Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 23 Sep 2016 18:07:03 +0100 Subject: [PATCH 1/3] Extract some utilities into a separate package --- .../InterpolateHtmlPlugin.js | 2 - packages/react-dev-utils/README.md | 180 ++++++++++++++++++ .../WatchMissingNodeModulesPlugin.js | 37 ++++ .../react-dev-utils/checkRequiredFiles.js | 32 ++++ packages/react-dev-utils/clearConsole.js | 18 ++ .../react-dev-utils/formatWebpackMessages.js | 67 +++++++ packages/react-dev-utils/openBrowser.js | 38 ++++ .../openChrome.applescript} | 2 - packages/react-dev-utils/package.json | 30 +++ .../utils => react-dev-utils}/prompt.js | 6 +- .../getClientEnvironment.js => config/env.js} | 0 .../config/webpack.config.dev.js | 8 +- .../config/webpack.config.prod.js | 6 +- packages/react-scripts/package.json | 2 +- packages/react-scripts/scripts/build.js | 7 +- packages/react-scripts/scripts/eject.js | 13 +- packages/react-scripts/scripts/start.js | 116 +++-------- packages/react-scripts/scripts/test.js | 2 +- .../utils/WatchMissingNodeModulesPlugin.js | 35 ---- .../scripts/utils/checkRequiredFiles.js | 33 ---- .../{scripts => }/utils/createJestConfig.js | 6 +- 21 files changed, 450 insertions(+), 190 deletions(-) rename packages/{react-scripts/scripts/utils => react-dev-utils}/InterpolateHtmlPlugin.js (96%) create mode 100644 packages/react-dev-utils/README.md create mode 100644 packages/react-dev-utils/WatchMissingNodeModulesPlugin.js create mode 100644 packages/react-dev-utils/checkRequiredFiles.js create mode 100644 packages/react-dev-utils/clearConsole.js create mode 100644 packages/react-dev-utils/formatWebpackMessages.js create mode 100644 packages/react-dev-utils/openBrowser.js rename packages/{react-scripts/scripts/utils/chrome.applescript => react-dev-utils/openChrome.applescript} (95%) create mode 100644 packages/react-dev-utils/package.json rename packages/{react-scripts/scripts/utils => react-dev-utils}/prompt.js (92%) rename packages/react-scripts/{scripts/utils/getClientEnvironment.js => config/env.js} (100%) delete mode 100644 packages/react-scripts/scripts/utils/WatchMissingNodeModulesPlugin.js delete mode 100644 packages/react-scripts/scripts/utils/checkRequiredFiles.js rename packages/react-scripts/{scripts => }/utils/createJestConfig.js (93%) diff --git a/packages/react-scripts/scripts/utils/InterpolateHtmlPlugin.js b/packages/react-dev-utils/InterpolateHtmlPlugin.js similarity index 96% rename from packages/react-scripts/scripts/utils/InterpolateHtmlPlugin.js rename to packages/react-dev-utils/InterpolateHtmlPlugin.js index bcb3a78a775..6ac587b3dc9 100644 --- a/packages/react-scripts/scripts/utils/InterpolateHtmlPlugin.js +++ b/packages/react-dev-utils/InterpolateHtmlPlugin.js @@ -1,4 +1,3 @@ -// @remove-on-eject-begin /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. @@ -7,7 +6,6 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -// @remove-on-eject-end // This Webpack plugin lets us interpolate custom variables into `index.html`. // Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })` diff --git a/packages/react-dev-utils/README.md b/packages/react-dev-utils/README.md new file mode 100644 index 00000000000..8c94e372c13 --- /dev/null +++ b/packages/react-dev-utils/README.md @@ -0,0 +1,180 @@ +# react-dev-utils + +This package includes some utilities used by [Create React App](https://github.com/facebookincubator/create-react-app). +Please refer to its documentation: + +* [Getting Started](https://github.com/facebookincubator/create-react-app/blob/master/README.md#getting-started) – How to create a new app. +* [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App. + +## Usage in Create React App Projects + +These utilities come by default with [Create React App](https://github.com/facebookincubator/create-react-app), which includes it by default. **You don’t need to install it separately in Create React App projects.** + +## Usage Outside of Create React App + +If you don’t use Create React App, or if you [ejected](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject), you may keep using these utilities. Their development will be aligned with Create React App, so major versions of these utilities may come out relatively often. Feel free to fork or copy and paste them into your projects if you’d like to have more control over them, or feel free to use the old versions. Not all of them are React-specific, but we might make some of them more React-specific in the future. + +### Entry Points + +There is no single entry point. You can only import individual top-level modules. + +#### `new InterpolateHtmlPlugin(replacements: {[key:string]: string})` + +This Webpack plugin lets us interpolate custom variables into `index.html`. +It works in tandem with [HtmlWebpackPlugin](https://github.com/ampedandwired/html-dev-plugin) 2.x via its [events](https://github.com/ampedandwired/html-dev-plugin#events). + +```js +var path = require('path'); +var HtmlWebpackPlugin = require('html-dev-plugin'); +var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); + +// Webpack config +var publicUrl = '/my-custom-url'; + +module.exports = { + output: { + // ... + publicPath: publicUrl + '/' + }, + // ... + plugins: [ + // Makes the public URL available as %PUBLIC_URL% in index.html, e.g.: + // + new InterpolateHtmlPlugin({ + PUBLIC_URL: publicUrl + // You can pass any key-value pairs, this was just an example. + // WHATEVER: 42 will replace %WHATEVER% with 42 in index.html. + }), + // Generates an `index.html` file with the