パッケージの詳細

nx-nextjs-node-loader

eisberg-labs5MIT1.0.0

Allows you to include native Node.js .node modules in your Next.js project in an NX monorepo.

webpack, nextjs, loader, node.js

readme

nextjs-node-loader

This is a custom loader for Webpack that allows you to include native Node.js .node modules in your Next.js project. It simplifies the process of loading native modules by providing a standardized interface that works seamlessly with Next.js. This is a modified version of Node loader. More context on the why and example use of the loader in my blog post.

Getting Started

To begin, you'll need to install a nextjs-node-loader:

npm install nextjs-node-loader --save-dev

next.config.js

module.exports = {
  webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
    config.module.rules.push({
      test: /\.node$/,
      use: [
        {
          loader: "nextjs-node-loader",
          options: {
            flags: os.constants.dlopen.RTLD_NOW,
            outputPath: config.output.path
          }
        },
      ],
    });
    return config;
  },
};

And use in e.g. your api route;

import module from "node-module";

export default function handler(req, res) {
  // ...
}

Options

Name Type Default Description
flags {Number} undefined Enables/Disables url/image-set functions handling
outputPath {String} webpack's outputPath The root path of shared node libraries

License

MIT

更新履歴

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.1.4 (2023-03-08)

Bug Fixes

  • wrong order of outputPath cond (07e34eb)

1.1.3 (2023-03-08)

Bug Fixes

  • fixes a unportable root path for native node modules (dcb44c2)

1.1.2 (2023-03-01)

Bug Fixes

1.1.1 (2023-03-01)

Bug Fixes

  • index.js: fix wrong export (b683307)

1.1.0 (2023-03-01)

Features

  • create nextjs-node-loader (bbf7a9d)