@@ -14,6 +14,26 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
14
14
var CaseSensitivePathsPlugin = require ( 'case-sensitive-paths-webpack-plugin' ) ;
15
15
var paths = require ( './paths' ) ;
16
16
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
+
17
37
module . exports = {
18
38
devtool : 'eval' ,
19
39
entry : [
@@ -107,6 +127,7 @@ module.exports = {
107
127
new webpack . DefinePlugin ( { 'process.env.NODE_ENV' : '"development"' } ) ,
108
128
// Note: only CSS is currently hot reloaded
109
129
new webpack . HotModuleReplacementPlugin ( ) ,
110
- new CaseSensitivePathsPlugin ( )
130
+ new CaseSensitivePathsPlugin ( ) ,
131
+ new RebuildOnPackageJSONChangePlugin ( paths . appPackageJson )
111
132
]
112
133
} ;
0 commit comments