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

@yolkai/nx-next

v9.2.0

Published

Nx plugin for Next.js

Downloads

13

Readme

nx-next

An Nx plugin for Next.js applications.

Nrwl publishes its own Next.js plugin, however it does not support launching a TypeScript custom server. With our own plugin, we have a simpler implementation and support for launching a TypeScript custom server.

Installation

npm install --save @yolkai/nx-next
# or
yarn add @yolkai/nx-next
# or
pnpm add @yolkai/nx-next

Usage

workspace.json:

{
  "version": 1,
  "projects": {
    "my-project": {
      "architect": {
        "build": {
          "builder": "@yolkai/nx-next:build",
          "options": {
            "root": "apps/my-project",
            "outputPath": "dist/apps/my-project"
          }
        },
        "customServer": {
          "builder": "@nrwl/node:build",
          "options": {
            "outputPath": "dist/apps/my-project/.server",
            "main": "apps/my-project/server/index.ts",
            "tsConfig": "apps/my-project/server/tsconfig.json",
            "assets": []
          }
        },
        "serve": {
          "builder": "@yolkai/nx-next:serve",
          "options": {
            "buildTarget": "my-project:build",
            "customServerTarget": "my-project:customServer",
            "port": 3007
          },
          "configurations": {
            "dev": {
              "dev": true,
              "skipBuild": false
            },
            "production": {
              "dev": false,
              "skipBuild": true
            },
            "coverage": {
              "dev": false
            }
          }
        },
        "dev": {
          "builder": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
              {
                "command": "node_modules/.bin/env-cmd --file apps/my-project/my-project.dev.env nx run my-project:serve:dev"
              }
            ]
          }
        }
      }
    }
  }
}

Builders

Build the Next.js app

Run this command prior to running the app in production mode.

nx run my-project:build

Build the custom server

If your app uses a custom server, run this command prior to running the app in production mode.

nx run my-project:customServer

Serve the app for development

The custom server will be built automatically before serving.

nx run my-project:serve:dev

Serve the app for production

nx run my-project:serve:production

Next.js config

// apps/my-project/next.config.js

const { withNx } = require('@yolkai/nx-next');
module.exports = withNx('my-project')({});

Custom server (optional)

// apps/my-project/server/index.ts

import { StartServerFn } from '@yolkai/nx-next';
import http from 'http';

const startServer: StartServerFn = async (nextApp, options) => {
  const handle = nextApp.getRequestHandler();
  await nextApp.prepare();
  const httpServer = http.createServer((req, res) => {
    handle(req, res);
  });

  return new Promise((resolve, reject) => {
    httpServer.on('error', (err: Error) => {
      if (err) {
        reject(err);
      }
    });
    httpServer.listen(options.port, () => {
      console.log(`listening on http://${options.host}:${options.port}`);
      resolve();
    });
  });
};

export { startServer };