22

I'm trying to figure out how to get webpack to watch an NPM linked dependency. I've tried to add an explicit entry pointing into the package, and I've tried to both explicitly included it and also not excluding /node_modules/ (which is quite common).

The scenario I want to achieve is as follows: I want to separate out parts of my react-based applications into component libraries (NPM packages).

Both the main package and the dependencies are written in ES6, so I've created a small gulp script that watches for changes in the dependent project, and transpiles its source (src/) to lib.

I've used npm link to wire in the dependent package so that I don't need to pack/publish/reinstall it every time I make a change.

When I make changes to the dependent package, the gulp tasks transpiles the code OK.

It is in the last part I am struggling; getting webpack watch to trigger a re-bundling when the dependency is refreshed by the forementioneds gulp task.

larsw
  • 3,790
  • 2
  • 25
  • 37
  • I'm having the same situation, do you have any way to solve it? I have a project like: a -> b -> c b depends on a, c depends on b. I want to be able to change a or b, and compile c once b is compiled. – singuerinc May 11 '17 at 07:13
  • 1
    Did we ever come up with a specific approach for resolving this? In the age of monorepos, it seems like an obvious issue. It'd be great if we had an example repo! – HipsterZipster Sep 19 '17 at 23:12
  • 1
    How about this https://stackoverflow.com/a/44166532/1248811 – Atav32 Jul 06 '18 at 18:40
  • 1
    The solution from @anytimecoder works – Sergio Rosas Dec 10 '18 at 22:01

1 Answers1

4

Make sure you transpiler script doesn't delete your old /lib dir, but overwrites files instead.

I had a similar problem with Webpack dev server not seeing changes because I was removing the /lib dir before every transpile.

anytimecoder
  • 7,204
  • 2
  • 14
  • 18
  • This works, just tried myself. In my case I'm working with Typescript Once I removed the "rimraf" removing the "lib" (or any name you have), it worked. I have webpack watching the final project, while TS watches the code from the linked dependency – Sergio Rosas Dec 10 '18 at 22:00