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/facebook/create-react-app/issues/186.
|
11 |
|
12 | ;
|
13 |
|
14 | class WatchMissingNodeModulesPlugin {
|
15 | constructor(nodeModulesPath) {
|
16 | this.nodeModulesPath = nodeModulesPath;
|
17 | }
|
18 |
|
19 | apply(compiler) {
|
20 | compiler.hooks.emit.tap('WatchMissingNodeModulesPlugin', compilation => {
|
21 | var missingDeps = Array.from(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.includes(nodeModulesPath))) {
|
26 | // ...tell webpack to watch node_modules recursively until they appear.
|
27 | compilation.contextDependencies.add(nodeModulesPath);
|
28 | }
|
29 | });
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = WatchMissingNodeModulesPlugin;
|