From 944fa46d0b29f22f4bf7476de8766b40053f8d1d Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 24 Oct 2016 01:36:25 -0400 Subject: [PATCH 1/2] Add BuildProgressPlugin --- .../react-dev-utils/BuildProgressPlugin.js | 30 +++++++++++++++++++ packages/react-dev-utils/package.json | 5 ++-- .../config/webpack.config.prod.js | 4 ++- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 packages/react-dev-utils/BuildProgressPlugin.js diff --git a/packages/react-dev-utils/BuildProgressPlugin.js b/packages/react-dev-utils/BuildProgressPlugin.js new file mode 100644 index 00000000000..49734bec5ad --- /dev/null +++ b/packages/react-dev-utils/BuildProgressPlugin.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * 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. + */ + +'use strict'; + +const ProgressPlugin = require('webpack').ProgressPlugin; +const ProgressBar = require('progress'); +const chalk = require('chalk'); + +function BuildProgressPlugin() { + const bar = new ProgressBar(` [:bar] ${chalk.bold(':percent')} ${chalk.yellow(':etas')} (${chalk.dim(':msg')})`, { + total: 100, + complete: '=', + incomplete: ' ', + width: 25 + }) + return new ProgressPlugin(function(percent, msg) { + if (percent === 1) msg = 'completed'; + bar.update(percent, { msg: msg }); + if (percent === 1) bar.terminate(); + }); +} + +module.exports = BuildProgressPlugin; diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 14c860999ae..8e1d3ca4b34 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -27,10 +27,9 @@ "escape-string-regexp": "1.0.5", "html-entities": "1.2.0", "opn": "4.0.2", + "progress": "1.1.8", "sockjs-client": "1.0.3", - "strip-ansi": "3.0.1" - }, - "peerDependencies": { + "strip-ansi": "3.0.1", "webpack": "^1.13.2" } } diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index e0141b851b4..107b2536c78 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -19,6 +19,7 @@ var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); var url = require('url'); var paths = require('./paths'); var getClientEnvironment = require('./env'); +var BuildProgressPlugin = require('react-dev-utils/BuildProgressPlugin'); function ensureSlash(path, needsSlash) { var hasSlash = path.endsWith('/'); @@ -257,7 +258,8 @@ module.exports = { // having to parse `index.html`. new ManifestPlugin({ fileName: 'asset-manifest.json' - }) + }), + new BuildProgressPlugin() ], // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works. From ee9ca5e7bce53d7c71321ae07ed84e26066b79b4 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 24 Oct 2016 13:05:16 -0400 Subject: [PATCH 2/2] Use react-scripts dependency before publish --- packages/react-dev-utils/BuildProgressPlugin.js | 11 +++++++++-- packages/react-dev-utils/package.json | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/react-dev-utils/BuildProgressPlugin.js b/packages/react-dev-utils/BuildProgressPlugin.js index 49734bec5ad..b0d5c984086 100644 --- a/packages/react-dev-utils/BuildProgressPlugin.js +++ b/packages/react-dev-utils/BuildProgressPlugin.js @@ -9,7 +9,14 @@ 'use strict'; -const ProgressPlugin = require('webpack').ProgressPlugin; +const path = require('path'); + +let ProgressPlugin; +if (__dirname.indexOf(path.join('packages', 'react-dev-utils')) !== -1) { + ProgressPlugin = require('../react-scripts/node_modules/webpack').ProgressPlugin; +} else { + ProgressPlugin = require('webpack').ProgressPlugin; +} const ProgressBar = require('progress'); const chalk = require('chalk'); @@ -22,7 +29,7 @@ function BuildProgressPlugin() { }) return new ProgressPlugin(function(percent, msg) { if (percent === 1) msg = 'completed'; - bar.update(percent, { msg: msg }); + bar.update(percent, { msg }); if (percent === 1) bar.terminate(); }); } diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 8e1d3ca4b34..b754dcdf207 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -29,7 +29,9 @@ "opn": "4.0.2", "progress": "1.1.8", "sockjs-client": "1.0.3", - "strip-ansi": "3.0.1", + "strip-ansi": "3.0.1" + }, + "peerDependencies": { "webpack": "^1.13.2" } }