如何使用捆绑中的 node_modules 依赖项正确构建用于生产的 NestJS 应用程序? [英] How to correctly build NestJS app for production with node_modules dependencies in bundle?

查看:19
本文介绍了如何使用捆绑中的 node_modules 依赖项正确构建用于生产的 NestJS 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nest buildnest build --webpack 之后 dist 文件夹不包含所有必需的模块,我收到 错误:找不到模块 '@nestjs/core' 尝试运行 node main.js 时.

After nest build or nest build --webpack dist folder does not contain all required modules and I got Error: Cannot find module '@nestjs/core' when trying to run node main.js.

我找不到关于 https://docs.nestjs.com/ 的任何明确说明正确构建用于生产的应用程序,所以我可能错过了什么?

I could not find any clear instructions on https://docs.nestjs.com/ on how to correctly build app for production, so maybe I missed something?

推荐答案

开箱即用,nest cli 不支持将 node_modules 依赖项包含到 dist 包中.

Out of the box, nest cli does not support including the node_modules dependencies into the dist bundle.

但是,有一些自定义 webpack 配置的社区示例,其中包含包中的依赖项,例如捆绑嵌套.如这个问题中所述,必须包含webpack.IgnorePlugin 将未使用的动态库列入白名单.

However, there are some community examples of custom webpack configs that include the dependencies in the bundle, e.g. bundled-nest. As described in this issue, it is necessary to include the webpack.IgnorePlugin to whitelist unused dynamic libraries.

这篇关于如何使用捆绑中的 node_modules 依赖项正确构建用于生产的 NestJS 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆