gpt4 book ai didi

node.js - zeit/pkg 如何捆绑我的 Node 应用程序?

转载 作者:行者123 更新时间:2023-12-02 10:30:00 25 4
gpt4 key购买 nike

这是我的第一个问题,所以首先打个招呼,如果我的问题不符合所有标准或看起来很尴尬,请原谅。

我想知道我的应用程序是如何与 zeit 的 pkg 捆绑和编译的。

bundle 是否插入到预先确定大小的二进制文件中?

它是否下载像 nexe 这样的 Node 源代码,并且代码是作为 main 运行还是在执行二进制文件时加载快照?

我有一个后端 Node-Express 服务器和一个前端 Angular 应用程序,每个应用程序都有自己的 Node_modules 文件夹,如下所示:

myapp
|-------/client
| |
| |-----/e2e
| |-----/node_modules
| |-----/src
|
|-------/config
|
|-------/node_modules
|
|-------/routes
|
|--app.js
|
|--package.json
|
|--README.md

pkg 如何处理 node_modules 的这两个实例?

非常感谢您的帮助/专业知识!

最佳答案

事实上有多个node_modules并不重要。在 app.js 中,require('foo') 引用 myapp/node_modules/foo。模块的捆绑方式与加载时解析的方式类似。

pkg 仅打包显式指定的模块。如the documentation州,

During packaging process pkg parses your sources, detects calls to require, traverses the dependencies of your project and includes them into executable. In most cases you don't need to specify anything manually. However your code may have require(variable) calls (so called non-literal argument to require) or use non-javascript files (for example views, css, images etc).

  require('./build/' + cmd + '.js')
path.join(__dirname, 'views/' + viewName)

Such cases are not handled by pkg. So you must specify the files - scripts and assets - manually in pkg property of your package.json file.

  "pkg": {
"scripts": "build/**/*.js",
"assets": "views/**/*"
}

Just be sure to call pkg package.json or pkg . to make use of scripts and assets entries.

不这样做将导致在打包过程中出现警告:

Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.

关于node.js - zeit/pkg 如何捆绑我的 Node 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51669770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com