Skip to content

Commit

Permalink
Rebuild project on package update (facebook#2956)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-ka committed Jan 29, 2018
1 parent 5348d6e commit 12b7c91
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
33 changes: 33 additions & 0 deletions packages/react-dev-utils/WatchChangedNodeModulesPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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.
*/

// This Webpack plugin ensures that any change in node_modules package.json forces a project rebuild.

'use strict';

var fs = require('fs');

var timeout;

class WatchChangedNodeModulesPlugin {
constructor(nodeModulesPath) {
this.nodeModulesPath = nodeModulesPath;
}

apply(compiler) {
fs.watch(
this.nodeModulesPath,
{ persistent: false, recursive: true },
() => {
clearTimeout(timeout);
timeout = setTimeout(() => compiler.run(() => {}), 1000);
}
);
}
}

module.exports = WatchChangedNodeModulesPlugin;
1 change: 1 addition & 0 deletions packages/react-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"openChrome.applescript",
"printHostingInstructions.js",
"WatchMissingNodeModulesPlugin.js",
"WatchChangedNodeModulesPlugin.js",
"WebpackDevServerUtils.js",
"webpackHotDevClient.js"
],
Expand Down
8 changes: 7 additions & 1 deletion packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const WatchChangedNodeModulesPlugin = require('react-dev-utils/WatchChangedNodeModulesPlugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const getClientEnvironment = require('./env');
Expand Down Expand Up @@ -333,11 +334,16 @@ module.exports = {
// a plugin that prints an error when you attempt to do this.
// See https://github.com/facebook/create-react-app/issues/240
new CaseSensitivePathsPlugin(),
// If you require a missing module and then `npm install` it, you still have
// If you require a missing module and then `yarn add` it, you still have
// to restart the development server for Webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebook/create-react-app/issues/186
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
// If you upgrade package version, you still have to restart the development
// server for Webpack to discover it. This plugin makes the discovery automatic
// so you don't have to restart.
// and https://github.com/facebook/create-react-app/issues/2956
new WatchChangedNodeModulesPlugin(paths.appNodeModules),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
Expand Down

0 comments on commit 12b7c91

Please sign in to comment.