fix: require errors with npm run build && npm run start
This commit is contained in:
parent
37ecf29c4d
commit
2816db6b92
@ -4,7 +4,7 @@
|
|||||||
"description": "WF Emulator",
|
"description": "WF Emulator",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node build/index.js",
|
"start": "node --import ./build/src/pathman.js build/src/index.js",
|
||||||
"dev": "ts-node-dev --openssl-legacy-provider -r tsconfig-paths/register src/index.ts ",
|
"dev": "ts-node-dev --openssl-legacy-provider -r tsconfig-paths/register src/index.ts ",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"lint": "eslint --ext .ts .",
|
"lint": "eslint --ext .ts .",
|
||||||
|
12
src/pathman.ts
Normal file
12
src/pathman.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Hooks node to support require from "@/" paths for `npm run build && npm run start`.
|
||||||
|
// Based on https://github.com/dividab/tsconfig-paths
|
||||||
|
|
||||||
|
const Module = require("module");
|
||||||
|
const originalResolveFilename = Module._resolveFilename;
|
||||||
|
Module._resolveFilename = function (request: string, _parent: any): string {
|
||||||
|
if (request.substring(0, 2) == "@/") {
|
||||||
|
const modifiedArguments = [process.cwd() + "/build/" + request.substr(2), ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
|
||||||
|
return originalResolveFilename.apply(this, modifiedArguments);
|
||||||
|
}
|
||||||
|
return originalResolveFilename.apply(this, arguments);
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user