UNPKG

1.1 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8// This Webpack plugin ensures `npm install <library>` forces a project rebuild.
9// We’re not sure why this isn't Webpack's default behavior.
10// See https://github.com/facebookincubator/create-react-app/issues/186.
11
12'use strict';
13
14class WatchMissingNodeModulesPlugin {
15 constructor(nodeModulesPath) {
16 this.nodeModulesPath = nodeModulesPath;
17 }
18
19 apply(compiler) {
20 compiler.plugin('emit', (compilation, callback) => {
21 var missingDeps = compilation.missingDependencies;
22 var nodeModulesPath = this.nodeModulesPath;
23
24 // If any missing files are expected to appear in node_modules...
25 if (missingDeps.some(file => file.indexOf(nodeModulesPath) !== -1)) {
26 // ...tell webpack to watch node_modules recursively until they appear.
27 compilation.contextDependencies.push(nodeModulesPath);
28 }
29
30 callback();
31 });
32 }
33}
34
35module.exports = WatchMissingNodeModulesPlugin;