简体   繁体   English

如何在不每次都构建的情况下使用 npm package 进行开发?

[英]How to use a npm package for development without building it every time?

I am using npm link to point to a local clone of the npm package.我正在使用npm link指向 npm package 的本地克隆。 In the package.json file of the npm package I have set the entrypoint to dist/index.js.在 npm 的 package.json 文件中 ZEFE90A8E604A7C840E88D03A6ZF6 的入口点设置为 7/D03A67F6 When I develop on the local version I don't want to rebuild the project every time.当我在本地版本上开发时,我不想每次都重建项目。 How can I solve this problem?我怎么解决这个问题?

Leave the package.json file entry point set to the dist/index.js file.package.json文件入口点设置为dist/index.js文件。

Then set a new scripts option in the package.json file to run tsc <filename> -w .然后在package.json文件中设置一个新的scripts选项来运行tsc <filename> -w This will run the TypeScript Compile command with the watch flag .这将运行带有watch 标志的 TypeScript 编译命令。 This will recompile when files change in the directory.当目录中的文件更改时,这将重新编译。

If you have a different flow that doesn't use tsc directly or doesn't support a watch flag then see the link below that uses nodemon .如果您有不直接使用tsc或不支持监视标志的不同流程,请参阅下面使用nodemon的链接。

https://stackoverflow.com/a/48255950/5779200 https://stackoverflow.com/a/48255950/5779200


You can't avoid the build process so it's best to embrace it and understand the advantages of not changing the entry point between the deployment and the development.您无法避免构建过程,因此最好接受它并了解不更改部署和开发之间的入口点的优势。

  • Simple flow, just press start, and your startup script should run it on its own简单的流程,只需按启动,您的启动脚本应该会自行运行
  • Same output in Prod and local development means less things to break Prod 和本地开发中的相同 output 意味着更少的事情要打破
  • Auto rebuilding on changes allow for faster development of not having to re-execute commands更改时自动重建允许更快的开发,而不必重新执行命令

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

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