![pnpm 9.5 Introduces Catalogs: Shareable Dependency Version Specifiers](https://cdn.sanity.io/images/cgdhsj6q/production/c06a5b74512bcc6da29d38cef96a454fa947810d-1024x1024.webp?w=400&fit=max&auto=format)
Security News
pnpm 9.5 Introduces Catalogs: Shareable Dependency Version Specifiers
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
node-loader
Advanced tools
Package description
The node-loader npm package is a loader for webpack that allows you to import Node.js modules in your webpack bundle. It enables the use of Node.js built-in modules and other Node.js-specific features within a webpack project.
Importing Node.js Modules
This feature allows you to import and use Node.js built-in modules like 'fs' within your webpack project. The code sample demonstrates reading a file synchronously using the 'fs' module.
const fs = require('fs');
const data = fs.readFileSync('/path/to/file', 'utf8');
console.log(data);
Using Node.js Specific Features
This feature enables the use of Node.js-specific features such as the 'path' module. The code sample shows how to join directory paths using the 'path' module.
const path = require('path');
const fullPath = path.join(__dirname, 'file.txt');
console.log(fullPath);
The webpack-node-externals package is a webpack plugin that excludes Node.js modules from the output bundle. It is useful for server-side applications where you want to keep the Node.js modules separate from the client-side bundle. Unlike node-loader, which allows importing Node.js modules, webpack-node-externals focuses on excluding them.
The babel-loader package is a webpack loader that allows you to transpile JavaScript files using Babel. While it does not specifically target Node.js modules, it can be used in conjunction with other loaders to handle modern JavaScript syntax and features. It complements node-loader by enabling the use of ES6+ syntax in Node.js modules.
Changelog
Readme
A Node.js add-ons loader.
Allows to connect native node modules with .node
extension.
⚠
node-loader
only works on thenode
/electron-main
/electron-main
targets.
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',
},
],
},
};
index.js
import node from 'node-loader!./file.node';
And run webpack
via your preferred method.
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.
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
][https://nodejs.org/api/process.html#process_process_dlopen_module_filename_flags] 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]';
},
},
},
],
},
};
Please take a moment to read our contributing guidelines if you haven't yet done so.
FAQs
Unknown package
We found that node-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
Security News
A threat actor on BreachForums is selling an unverified npm vulnerability for account takeover, but npm has not officially confirmed the existence of this security concern.
Security News
Cyber insurance rates are dropping as the market matures, according to a new report projecting global premiums to reach $43 billion by 2030, driven by international market uptake and growth in the SME sector.