All Projects → ushu → Node Addon Loader

ushu / Node Addon Loader

Licence: mit
A loader for node native addons

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Addon Loader

Webpack Conditional Loader
C conditionals directive for JavaScript
Stars: ✭ 93 (+447.06%)
Mutual labels:  webpack, webpack2, webpack-loader
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (+1870.59%)
Mutual labels:  webpack, webpack2, webpack-loader
Webpack.js.org
Repository for webpack documentation and more!
Stars: ✭ 2,049 (+11952.94%)
Mutual labels:  webpack, webpack2, webpack-loader
Bootstrap Loader
Load Bootstrap styles and scripts in your Webpack bundle
Stars: ✭ 1,038 (+6005.88%)
Mutual labels:  webpack, webpack2, webpack-loader
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (+452.94%)
Mutual labels:  webpack, webpack2, webpack-loader
Svg Sprite Loader
Webpack loader for creating SVG sprites.
Stars: ✭ 1,822 (+10617.65%)
Mutual labels:  webpack, webpack2, webpack-loader
String Replace Loader
Replace loader for Webpack
Stars: ✭ 205 (+1105.88%)
Mutual labels:  webpack, webpack2, webpack-loader
React Dynamic Route Loading Es6
Auto chunking and dynamic loading of routes with React Router and Webpack 2
Stars: ✭ 297 (+1647.06%)
Mutual labels:  webpack, webpack2
Extract Loader
webpack loader to extract HTML and CSS from the bundle
Stars: ✭ 297 (+1647.06%)
Mutual labels:  webpack, webpack-loader
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (+1700%)
Mutual labels:  webpack, webpack2
Awesome Webpack Cn
[印记中文](https://docschina.org/) - webpack 优秀中文文章
Stars: ✭ 3,611 (+21141.18%)
Mutual labels:  webpack, webpack2
exif-loader
Extract EXIF- & IPTC-data from your JPGs during build-time.
Stars: ✭ 14 (-17.65%)
Mutual labels:  webpack-loader, webpack2
Vue Template Loader
Vue.js 2.0 template loader for webpack
Stars: ✭ 253 (+1388.24%)
Mutual labels:  webpack, webpack-loader
Suddi.github.io
A static single-page application resume-builder developed using React.js and JSON Resume schema (https://suddi.io/)
Stars: ✭ 246 (+1347.06%)
Mutual labels:  webpack, webpack2
One Loader
Single-file components for React
Stars: ✭ 233 (+1270.59%)
Mutual labels:  webpack, webpack-loader
Vueniverse
Full stack, user based, PWA, Vue template.
Stars: ✭ 339 (+1894.12%)
Mutual labels:  webpack, webpack2
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+21770.59%)
Mutual labels:  webpack, webpack-loader
Browser Sync Webpack Plugin
Easily use BrowserSync in your Webpack project.
Stars: ✭ 356 (+1994.12%)
Mutual labels:  webpack, webpack2
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+2505.88%)
Mutual labels:  webpack, webpack2
Koa Webpack
Development and Hot Reload Middleware for Koa2
Stars: ✭ 429 (+2423.53%)
Mutual labels:  webpack, webpack2

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].