Skip to content

Commit 6b51f30

Browse files
committed
Force rebuild after npm install
Fixes #186
1 parent 0dacfe3 commit 6b51f30

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

config/webpack.config.dev.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var autoprefixer = require('autoprefixer');
1212
var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
15+
var WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
1516
var paths = require('./paths');
1617

1718
module.exports = {
@@ -107,6 +108,7 @@ module.exports = {
107108
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' }),
108109
// Note: only CSS is currently hot reloaded
109110
new webpack.HotModuleReplacementPlugin(),
110-
new CaseSensitivePathsPlugin()
111+
new CaseSensitivePathsPlugin(),
112+
new WatchMissingNodeModulesPlugin(paths.appNodeModules)
111113
]
112114
};

scripts/eject.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ prompt(
4444
path.join('scripts', 'build.js'),
4545
path.join('scripts', 'start.js'),
4646
path.join('scripts', 'utils', 'chrome.applescript'),
47-
path.join('scripts', 'utils', 'prompt.js')
47+
path.join('scripts', 'utils', 'prompt.js'),
48+
path.join('scripts', 'utils', 'WatchMissingNodeModulesPlugin.js')
4849
];
4950

5051
// Ensure that the app folder is clean and we won't override any files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
// This Webpack plugin ensures `npm install <library>` forces a project rebuild.
11+
// We’re not sure why this isn't Webpack's default behavior.
12+
// See https://github.com/facebookincubator/create-react-app/issues/186.
13+
14+
function WatchMissingNodeModulesPlugin(nodeModulesPath) {
15+
this.nodeModulesPath = nodeModulesPath;
16+
}
17+
18+
WatchMissingNodeModulesPlugin.prototype.apply = function (compiler) {
19+
compiler.plugin('emit', (compilation, callback) => {
20+
var missingDeps = compilation.missingDependencies;
21+
var nodeModulesPath = this.nodeModulesPath;
22+
23+
// If any missing files are expected to appear in node_modules...
24+
if (missingDeps.some(file => file.indexOf(nodeModulesPath) !== -1)) {
25+
// ...tell webpack to watch node_modules recursively until they appear.
26+
compilation.contextDependencies.push(nodeModulesPath);
27+
}
28+
29+
callback();
30+
});
31+
}
32+
33+
module.exports = WatchMissingNodeModulesPlugin;

0 commit comments

Comments
 (0)