简体   繁体   English

如何指示webpack观察NPM链接依赖项(包)中的更改

[英]How to instruct webpack to watch changes in an NPM linked dependency (package)

I'm trying to figure out how to get webpack to watch an NPM linked dependency. 我试图找出如何让webpack观看NPM链接依赖项。 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). 我试图添加一个指向包的显式条目,我试图明确地包含它,也不排除/ node_modules /(这是很常见的)。

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). 我想要实现的场景如下:我想将基于反应的应用程序的一部分分离到组件库(NPM包)中。

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. 主程序包和依赖项都是用ES6编写的,所以我创建了一个小的gulp脚本,它监视依赖项目中的变化,并将其源代码(src /)转换为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. 我已经使用npm链接在依赖包中连接,这样我每次进行更改时都不需要打包/发布/重新安装它。

When I make changes to the dependent package, the gulp tasks transpiles the code OK. 当我对依赖包进行更改时,gulp任务会将代码转换为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. 当前面提到的gulp任务刷新依赖关系时,让webpack watch触发重新捆绑。

Make sure you transpiler script doesn't delete your old /lib dir, but overwrites files instead. 确保您的转换脚本不会删除旧的/lib目录,而是覆盖文件。

I had a similar problem with Webpack dev server not seeing changes because I was removing the /lib dir before every transpile. 我有一个类似的问题,Webpack dev服务器没有看到更改,因为我在每次转换之前删除/lib目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM