npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rnw-community/nestjs-webpack-swc

v0.70.0

Published

NestJS typed config

Downloads

766

Readme

NestJS Webpack + SWC configuration

NestJS webpack and SWC configuration helpers, this can speed up your local NestJS development up to 10x.

npm version npm downloads

  • NestJS offers Webpack configuration with HMR which significantly improves rebuild speed within local development especially if your project grows.
  • SWC is next generation of fast developer tools which transpiles typescript blazingly fast compared to Babel, and it has webpack swc-loader

This package helps to easily configure NestJS webpack and SWC integration and make you DX good and quick again

Installation

  1. Install package @rnw-community/nestjs-webpack-swc using your package manager
  2. Install additional peer dependencies:

Configuration

Development webpack configuration

Create webpack-dev.config.js in root of the NestJS package:

module.exports = require('@rnw-community/nestjs-webpack-swc/get-nestjs-webpack-dev.config').getNestJSWebpackDevConfig;

Production webpack configuration

Create webpack-prod.config.js in root of the NestJS package:

module.exports = require('@rnw-community/nestjs-webpack-swc/get-nestjs-webpack-prod.config').getNestJSWebpackProdConfig;

NestJS HMR

For blazing fast DX, this package provides utility to simplify HMR configuration:

import { handleNestJSWebpackHmr } from '@rnw-community/nestjs-webpack-swc';

const bootstrap = async (): Promise<void> => {
    //...
    handleNestJSWebpackHmr(app, module);
};

Scripts package.json

Change package.json build, start:dev scripts:

{
    "build": "nest build --webpack --webpackPath webpack-prod.config.js",
    "start:dev": "nest build --webpack --webpackPath webpack-dev.config.js --watch"
}

.gitignore

For maximum speed webpack is configured to generate filesystem cache and uses .build_cache folder in package root, so you need to add it to your .gitignore file.

Possible webpack issues

Due to webpack bundling approach you may encounter problems with packages that use absolute/relative paths, each of this cases needs separate solutions. Feel free to open an issue.

Typeorm migrations

If your project is using TypeORM, then you will face problems with running migrations from NestJS app, this package provides utility for loading TypeORM migrations within webpack build.

  1. Install additional dev dependencies:
  1. Add this package to your tsconfig.*.json files:
{
    "compilerOptions": {
        "types": ["node", "@types/webpack-env"]
    }
}
  1. Add code that will return class instances array that you can pass to TypeORM configuration, you will only need to provide path to the folder where all migrations are stored:
const migrations = importTypeormWebpackMigrations(require.context('./migration/', true, /\.ts$/u));

Typeorm CLI

With webpack in place you will not have your migrations transpiled into the dist folder anymore so to use typeorm cli you will need additional changes:

  1. Install additional dev dependencies:
  2. Add/change your package.json scripts(you should have tsconfig.build.json with module:commonjs):
{
    "scripts": {
        "typeorm": "ts-node -P tsconfig.build.json -r tsconfig-paths/register ./node_modules/.bin/typeorm",
        "migrate:create": "yarn typeorm migration:create -d ./data-source.mjs",
        "migrate:down": "yarn typeorm migration:revert -d ./data-source.mjs",
        "migrate:generate": "yarn typeorm migration:generate -d ./data-source.mjs",
        "migrate:up": "yarn typeorm migration:run -d ./data-source.mjs"
    }
}

-d ./data-source.mjs is a TypeORM v3 breaking changes you can remove it for v2

SWC possible issues

SWC bindings

If your project is running inside the docker container and your host system has different architecture you may end up with Error: Bindings not found SWC error, this is happening because when you install SWC it uses the bindings for your host machine, to fix this:

  1. Create .yarnrc file in the project root:
--ignore-engines true
--ignore-platform true
  1. Add swc bindings dependencies:
{
    "@swc/core-linux-arm64-musl": "^1.2.242",
    "@swc/core-linux-x64-musl": "^1.2.242"
}

License

This library is licensed under The MIT License.