Skip to content

Commit eed6984

Browse files
committed
Force rebuild on package.json changes
Partially fixes #186
1 parent 01eeb61 commit eed6984

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

config/webpack.config.dev.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
1414
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1515
var paths = require('./paths');
1616

17+
// We don't watch node_modules by default because it's too slow.
18+
// However if a dependency is missing, and the user npm installs it,
19+
// we want to rebuild the app and disregard the cached "module not found".
20+
// This custom plugin does the job.
21+
// Relevant issue: https://github.com/facebookincubator/create-react-app/issues/186
22+
function RebuildOnPackageJSONChangePlugin(packageJsonPath) {
23+
this.packageJsonPath = packageJsonPath;
24+
}
25+
RebuildOnPackageJSONChangePlugin.prototype.apply = function (compiler) {
26+
compiler.plugin('emit', (compilation, callback) => {
27+
compilation.fileDependencies.push(this.packageJsonPath);
28+
callback();
29+
});
30+
compiler.plugin('done', stats => {
31+
if (stats.compilation.missingDependencies.length) {
32+
compiler.inputFileSystem.purge();
33+
}
34+
});
35+
}
36+
1737
module.exports = {
1838
devtool: 'eval',
1939
entry: [
@@ -107,6 +127,7 @@ module.exports = {
107127
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' }),
108128
// Note: only CSS is currently hot reloaded
109129
new webpack.HotModuleReplacementPlugin(),
110-
new CaseSensitivePathsPlugin()
130+
new CaseSensitivePathsPlugin(),
131+
new RebuildOnPackageJSONChangePlugin(paths.appPackageJson)
111132
]
112133
};

0 commit comments

Comments
 (0)