{"id":16535392,"url":"https://github.com/zensoftware/bundled-nest","last_synced_at":"2025-03-21T09:32:11.289Z","repository":{"id":41425863,"uuid":"206973003","full_name":"ZenSoftware/bundled-nest","owner":"ZenSoftware","description":"💥 Nest 🔰 Webpack 🔰 Docker 💥 --- 🏯 Now archived for historical reference ⛩","archived":false,"fork":false,"pushed_at":"2021-01-24T21:44:37.000Z","size":141,"stargazers_count":70,"open_issues_count":3,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T05:05:37.144Z","etag":null,"topics":["docker","nest","nestjs","webpack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZenSoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-07T13:36:05.000Z","updated_at":"2024-12-07T04:17:49.000Z","dependencies_parsed_at":"2022-09-21T08:32:30.521Z","dependency_job_id":null,"html_url":"https://github.com/ZenSoftware/bundled-nest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenSoftware%2Fbundled-nest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenSoftware%2Fbundled-nest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenSoftware%2Fbundled-nest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenSoftware%2Fbundled-nest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZenSoftware","download_url":"https://codeload.github.com/ZenSoftware/bundled-nest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130281,"owners_count":20402753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","nest","nestjs","webpack"],"created_at":"2024-10-11T18:27:20.127Z","updated_at":"2025-03-21T09:32:10.998Z","avatar_url":"https://github.com/ZenSoftware.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 💥 Nest 🔰 Webpack 🔰 Docker 💥\n\n## 🏯 Now archived for historical reference ⛩\n\nWe've concluded that it is not recommended to bundle NestJS, or actually, NodeJS web servers in general. This is archived for historical reference during the period of time when the community was attempting to tree-shake, and bundle NestJS apps. Refer to [@kamilmysliwiec comment](https://github.com/nestjs/nest/issues/1706#issuecomment-579248915) for details:\n\n\u003e In many real-world scenarios (depending on what libraries are being used), you should not bundle Node.js applications (not only NestJS applications) with all dependencies (external packages located in the node_modules folder). Although this may make your docker images smaller (due to tree-shaking), somewhat reduce the memory consumption, slightly increase the bootstrap time (which is particularly useful in the serverless environments), it won't work in combination with many popular libraries commonly used in the ecosystem.\n\u003e For instance, if you try to build NestJS (or just express) application with MongoDB, you will see the following error in your console:\n\u003e\n\u003e ```\n\u003e Error: Cannot find module './drivers/node-mongodb-native/connection'\n\u003e at webpackEmptyContext\n\u003e ```\n\u003e\n\u003e Why? Because mongoose depends on mongodb which depends on kerberos (C++) and node-gyp.\n\n---\n\nFor an example of how to build an enterprise-grade tech stack, please check out my new project:\n## [⛩ Zen ⛩ Nest + Prisma + Angular 🏮 Full Stack Starter Kit](https://github.com/ZenSoftware/Zen)\n\n---\n\n# Historical reference...\n\nThis repo is a starting point for others who wish to build a [Nest](https://github.com/nestjs/nest) app with minimal footprint. Bundling dependencies with Webpack, and containerized for Docker.\n\n|                                                                                 |    Size     |\n| ------------------------------------------------------------------------------- | :---------: |\n| production bundle of a `main.js` \"Hello World!\"                                 | **1.49 MB** |\n| Containerized as a Docker image [node:12-alpine](https://hub.docker.com/_/node) | **81.9 MB** |\n\nThe Alpine variant of Node.js - Docker base image is being used for minimal footprint. Node.js v12 has improved startup times over an already performant startup process. This enables Nest to be an excellent solution for a microservice architecture. Allowing for efficient spinning up of new Kubernetes pods to meet compute demands, and disposed as necessary. Written in Typescript, Nest allows for a more familiar, and declarative development experience for writing modern web services. Check out the [official docs](https://docs.nestjs.com/) to learn more.\n\nThis repo demonstrates the minimal amount needed to integrate a bundling system and containerize the app as a Docker image. Though for commercial projects, I would strongly suggest using a project management tool like Nx, by the company Nrwl. [Getting Started with Nx](https://nx.dev/angular/getting-started/getting-started). It makes full stack development with Nest simple. Nest schematics even work with [Angular Console - VS Code Extension](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console), with zero configuration needed.\n\n#\n\nThis repo is produced from a fresh `nest new` command, using [nest-cli](https://docs.nestjs.com/cli/usages), with minimal modifications. Currently there are some intricacies with bundling dependencies for a Nest app. [(Issue: #1706)](https://github.com/nestjs/nest/issues/1706) Comments are included in the `Dockerfile` and `webpack.config.json` for clarification. This repo addresses the known issues for you. 🥂\n\nThe following packages were added to the default `package.json`.\n\n```bash\nwebpack@latest\nwebpack-cli@latest\nts-loader@latest\ntsconfig-paths-webpack-plugin@latest  # For targeting \"tsconfig.build.json\"\n```\n\n3 scripts have been added to the `package.json`\n\n```bash\n# Bundle with webpack\nnpm run build:prod\n\n# Build the docker image\nnpm run docker:build\n\n# Run the docker image\nnpm run docker:run\n```\n\nFor containerization, ensure your app uses the port from the environment if it exists.\n\n**\"main.ts\"**\n\n```ts\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n\n  // For Docker containerization\n  const PORT = process.env.PORT || 3000;\n  await app.listen(PORT);\n\n  console.log(`Server is running at http://localhost:${PORT}`);\n}\nbootstrap();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzensoftware%2Fbundled-nest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzensoftware%2Fbundled-nest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzensoftware%2Fbundled-nest/lists"}