简体   繁体   English

构建或打包一个nodejs脚本,使其独立

[英]Build or pack a nodejs script so that it is self-contained

I have a javascript codebase with a structure like this: 我有一个具有以下结构的javascript代码库:

node_modules/
src/
   /script1
   /script2
   /script3
package.json
package.lock
.env

etc... 等等...

The scripts are simple utilities that sometimes include code from each other's folders to maximize code reuse. 脚本是简单的实用程序,有时会包含彼此文件夹中的代码以最大程度地重复使用代码。 Even if they didn't do that, they share the same node_modules folder so they are entangled anyway. 即使他们没有这样做,他们也会共享相同的node_modules文件夹,因此无论如何它们都会纠缠在一起。

I want to run something like webpack on /script2 (but without targeting the web) so that all its unique dependencies are inlined as one massive JS script... (Or failing that, build its unique dependencies to output its own node_modules and package.json files... but that sounds way more complex). 我想在/script2 script2上运行类似webpack的东西(但不针对Web),以便将其唯一的依赖项作为一个大型JS脚本内联...(否则,构建其唯一的依赖项以输出自己的node_modules和包。 json文件...但是听起来更复杂)。

How do I keep the current project structure but still build standalone pieces as needed, for different environments (mainly serverless functions)? 如何保留当前的项目结构,但仍根据需要针对不同的环境(主要是无服务器功能)构建独立的项目? Thanks. 谢谢。

基本上,您可以在每个文件上将webpack作为条目运行,并将webpack配置为与node目标一起使用。

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

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