1.0.2 • Published 2 years ago

build-native-node-modules-nextjs v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

build-native-node-modules-nextjs

Forked and updated from https://github.com/eisberg-labs/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.

Getting Started

To begin, you'll need to install a build-native-node-modules-nextjs:

npm install build-native-node-modules-nextjs --save-dev

next.config.js

module.exports = {
  webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
    config.module.rules.push({
      test: /\.node$/,
      use: [
        {
          loader: "build-native-node-modules-nextjs",
          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

NameTypeDefaultDescription
flags{Number}undefinedEnables/Disables url/image-set functions handling
outputPath{String}webpack's outputPathThe root path of shared node libraries
includeWebpackPublicPath{String}falseIf webpack_public_path should be included in a path for loading node module. For nextjs >13.2.5 should be false.

License

MIT

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago