2.0.0 • Published 3 years ago

node-loader v2.0.0

Weekly downloads
101,899
License
MIT
Repository
github
Last release
3 years ago

npm node deps tests coverage chat 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/electron-main/electron-main targets.

Getting Started

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

$ npm install node-loader --save-dev

Setup the target option to node/electron-main/electron-main 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

NameTypeDefaultDescription
flags{Number}undefinedEnables/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

@theia/application-manager@boris47/electron-webpackbetter-electron-webpackmagic-home-scaffold@aethernet/electron-webpack@infinitebrahmanuniverse/nolb-node-l@everything-registry/sub-chunk-2305ct_baseui@junvary/quasar-ui-qcascader@kui-shell/webpackquasar-cli@langtrase/typescript-sdk@rws-framework/serverskypager-frameworkskypager-webpackrosbag_next@r3m0t/vscode-python@richlox/core@rockpack/compiler@pravdomil/blocksrudongui@skysong/mc-cli@loopmode/electron-webpack@mongodb-js/webpack-config-compass@monospaces/electron-webpack@monstrs/code-runtime@monstrs/tools-runtime@moviecast/electron-webpack@joelwat/quasar-app@keystore/react-tool@keystore/toolreact-electron-chunky@micro-app/plugin-webpack@nuggxyz/dotnugg-sdk@ludum_studios/brix-navigation@ludum_studios/brix-physics@kythuen/webpack-builder@not-govuk/webpack-config@quasar/app@quasar/app-webpackspectiql@turbowarp/electron-webpack@wpefintech/figma2html@paulwib/electron-webpackrocket-starterrws-js-servervue-toast-demo-dongdongexplorer-uielan-clieasy-create-sharkelectron-webpackelectron-webpack-releaseelectron-webpack-v2eh-dockerdocument-builderdetect-fullscreen-tshome-portal-services-1hx-wallet-desktop@eventbrite/brite-core@fay-react/toolgoblin-webpackgulp-assistantlentil-macos-additionslentil-os-additionskirbo-electron-webpackkevm-ganache-clijsvh-cs-frontend-only-jsmyquasarv1app@ekz/packernuxtjs-electronp2h4kpairsync@intlayer/chokidar@intlayer/webpack@01/core-utils@a1motion/electron-kit@albertli90/react-electron-scriptsbackendconfigvue-toast-liartifact-tracer@yck-web/deploy-kc@wasc/toolsbjgridwebnoob-q-app@bazumax/quasar-appwisdom-vuewebpack-cli-utilwebpack-clis-utilswebpack-test-demo1cnki-uiyach.clixea-cli-view-service@darwishdev/dash-dev@delewis13/electron-webpack@heat/awsless@horoshop/appdappctrlgui
2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.6.0

8 years ago

0.5.0

11 years ago