GithubHelp home page GithubHelp logo

ersachin3112 / node-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webpack-contrib/node-loader

0.0 0.0 0.0 763 KB

node loader for native modules

License: MIT License

JavaScript 98.54% Shell 1.46%

node-loader's Introduction

npm node tests coverage discussion size

node-loader

A Node.js add-ons loader.

Allows to connect native node modules with .node extension.

โš  node-loader only works on the node/async-node/electron-main/electron-renderer/electron-preload targets.

Getting Started

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

npm install node-loader --save-dev

or

yarn add -D node-loader

or

pnpm add -D node-loader

Setup the target option to node/async-node/electron-main/electron-renderer/electron-preload value and do not mock the __dirname global variable.

webpack.config.js

module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
      },
    ],
  },
};

Inline

index.js

import node from "node-loader!./file.node";

And run webpack via your preferred method.

Configuration

index.js

import node from "file.node";

Then add the loader to your webpack config. For example:

webpack.config.js

module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
      },
    ],
  },
};

And run webpack via your preferred method.

Options

Name Type Default Description
flags {Number} undefined Enables/Disables url/image-set functions handling
name {String|Function} '[contenthash].[ext]' Specifies a custom filename template for the target file(s).

flags

Type: Number Default: undefined

The flags argument is an integer that allows to specify dlopen behavior. See the process.dlopen documentation for details.

index.js

import node from "file.node";

webpack.config.js

const os = require("os");

module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
        options: {
          flags: os.constants.dlopen.RTLD_NOW,
        },
      },
    ],
  },
};

name

Type: String|Function Default: '[contenthash].[ext]'

Specifies a custom filename template for the target file(s).

String

webpack.config.js

module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
        options: {
          name: "[path][name].[ext]",
        },
      },
    ],
  },
};

Function

webpack.config.js

module.exports = {
  target: "node",
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
        options: {
          name(resourcePath, resourceQuery) {
            // `resourcePath` - `/absolute/path/to/file.js`
            // `resourceQuery` - `?foo=bar`

            if (process.env.NODE_ENV === "development") {
              return "[path][name].[ext]";
            }

            return "[contenthash].[ext]";
          },
        },
      },
    ],
  },
};

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

node-loader's People

Contributors

alexander-akait avatar amareshsm avatar anshumanv avatar cap-bernardito avatar dependabot[bot] avatar dummyc0m avatar ersachin3112 avatar evilebottnawi avatar gohan avatar joshwiens avatar kevinzwhuang avatar kevzettler avatar michael-ciniawsky avatar michaeljones avatar shellscape avatar simon04 avatar snitin315 avatar sokra avatar spacek33z avatar thelarkinn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.