@repugraf/rewrite-esm-paths
v1.0.1
Published
Adds extensions in esm imports/exports
Downloads
2
Maintainers
Readme
Rewrite ESM Paths
This issue this package is solving mostly caused typescript inability to rewrite imports/exports when building to esm target.
Example
This TypeScript code:
import Package from "./package";
Will stay the same when built to esm. This will not work when running inside nodejs in esm context.
Here is the desired output:
import Package from "./package.js";
More info about this issue can be found on this thread
Usage
import { resolve } from "fs";
import { addExtToFilesRecursive } from "@repugraf/rewrite-esm-paths";
const absoluteDirectoryPath = resolve(__dirname, "..", "lib", "esm");
addExtToFilesRecursive(absoluteDirectoryPath, "js");
Caveats
- The package will not follow
index.js
imports. You need to specify full path to your files in your imports - Bare imports from
node_modules
will stay unchanged