Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit dcb44c2

Browse files
committed
fix: fixes a unportable root path for native node modules
1 parent 5d3f9c5 commit dcb44c2

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is a modified version of [Node loader](https://github.com/webpack-contrib/n
77

88
## Getting Started
99

10-
To begin, you'll need to install `nextjs-node-loader`:
10+
To begin, you'll need to install a `nextjs-node-loader`:
1111

1212
```console
1313
npm install nextjs-node-loader --save-dev
@@ -23,6 +23,10 @@ module.exports = {
2323
use: [
2424
{
2525
loader: "nextjs-node-loader",
26+
options: {
27+
flags: os.constants.dlopen.RTLD_NOW,
28+
outputPath: config.output.path
29+
}
2630
},
2731
],
2832
});
@@ -43,24 +47,10 @@ export default function handler(req, res) {
4347

4448
## Options
4549

46-
| Name | Type | Default | Description |
47-
| :-------------------: | :--------: | :---------: | :---------------------------------------------------- |
48-
| **[`flags`](#flags)** | `{Number}` | `undefined` | Enables/Disables `url`/`image-set` functions handling |
49-
50-
### `flags`
51-
52-
Type: `Number`
53-
Default: `undefined`
54-
55-
The `flags` argument is an integer that allows to specify dlopen behavior.
56-
See the [`process.dlopen`](https://nodejs.org/api/process.html#process_process_dlopen_module_filename_flags)
57-
documentation for details.
58-
59-
## Contributing
60-
61-
Please take a moment to read our contributing guidelines if you haven't yet done so.
62-
63-
[CONTRIBUTING](./.github/CONTRIBUTING.md)
50+
| Name | Type | Default | Description |
51+
|:----------:|:----------:|:--------------------:| :---------------------------------------------------- |
52+
| flags | `{Number}` | `undefined` | Enables/Disables `url`/`image-set` functions handling |
53+
| outputPath | `{String}` | webpack's outputPath | The root path of shared node libraries |
6454

6555
## License
6656

src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const schema = require("./options.json");
55
export default function loader(content) {
66
const { rootContext, _compiler, getOptions, emitFile } = this;
77
const options = getOptions(schema);
8-
const { flags } = options;
9-
const outputPath = _compiler.options.output.path;
8+
const { flags, outputPath } = options;
109

1110
const name = interpolateName(this, "[name].[ext]", {
1211
context: rootContext,
@@ -18,7 +17,7 @@ export default function loader(content) {
1817
return `
1918
try {
2019
process.dlopen(module, ${JSON.stringify(
21-
outputPath
20+
typeof outputPath !== "undefined" ? _compiler.options.output.path : outputPath,
2221
)} + require("path").sep + __webpack_public_path__ + ${JSON.stringify(name)}${
2322
typeof flags !== "undefined" ? `, ${JSON.stringify(options.flags)}` : ""
2423
});

src/options.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
2-
"title": "Node Loader options",
2+
"title": "Nextjs Node Loader options",
33
"type": "object",
44
"properties": {
55
"flags": {
66
"type": "integer",
7-
"description": "An integer value that allows to specify dlopen behavior.",
8-
"link": "https://github.com/webpack-contrib/node-loader#flags"
7+
"description": "An integer value that allows to specify dlopen behavior."
8+
},
9+
"outputPath": {
10+
"type": "string",
11+
"description": "The root path of shared node libraries"
912
}
1013
},
1114
"additionalProperties": false

0 commit comments

Comments
 (0)