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

@s524797336/node-addon-loader

v1.0.0

Published

A loader of node native addons

Downloads

2

Readme

A simple loader to embed native addons in node or electron projects.

This package is a mix between:

  • node-loader that loads a node module from an absolute path
  • file-loader that loads copy a file into the bundle and return its path

This one package allows to load a node native addon, binary file will end up copied into the output directory and loaded dynamically from its relative path.

Install

Add the package to your package.json

$ yarn add --dev node-addon-loader

Usage

Add the loader to your webpack.config.js for all .node native files.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.node$/,
        use: 'node-addon-loader',
        options: [
          basePath: resolve(__dirname),
        ]
      }
    ]
  }
}

Note the basePath option: it will instruct the loader of the "base" path, from where the node runtime will be started. It will generate loading path relative to this URL. For example is you develop an electron app with a bundle emitted into dist/ directory, you want all the required paths (emitted require statements) to be relative to the current directory of the electron runtime (they all will be like dist/xxxx.node).

In your application

You require the file directly

import node from 'relative/path/to/myLib.node';
// or
const node = require("relative/path/to/myLib.node");

or with the inline syntax:

Inline

import node from 'node-addon-loader!./myLib.node';

with an alias

a good option is to keep your modules in some place and create aliases for them, such as:

// webpack config
module.exports = {

  resolve: {
    alias: {
    "myLib": "/path/to/myLib.node",
    }
  },

  // ...

}

and then use your alias directly:

import myLib from "myLib";

Thanks

big thanks go the the authors of node-loader and file-loader which I eagerly copied.

TODO

Fix the issue with emitFile, see TODO in code.

All contributions are welcome, this is MIT do-whatever-you-want-I-dont-care code.