mkdist
mkdist copied to clipboard
Improve import extension normalization
mkdist uses a post-build transform to add explicit extensions (src) but this is not always working (eg with multi line imports) https://github.com/unjs/unbuild/issues/83.
We shall migrate to mlly.parseStaticImports.
You mean that we will improve like this.
{ builder: "mkdist", input: "./src/common", name: "untils", outDir: "common", ext: "cjs", format: "cjs", },
But after build, I see code built not imported with extension.
var _other = require("../constants/other");
So we need to update to: var _other = require("../constants/other.cjs");
Right man?
@hieusmiths Explicit .cjs extensions should be added in last version try upgrading.
If rewrite is still not working, please share your source code snippet 🙏
Facing with the same. @pi0 , but I am not understand why shall migrate to mlly.parseStaticImports. Is it possible to just improve the regx pattern
output.contents = output.contents!.replace(
/(import|export)(.* from ["'])(.*)(["'])/g,
(_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
);
into
output.contents = output.contents!.replace(
/(import|export)([\s\S]* from ["'])(.*)(["'])/g,
(_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
);
It seems worked.
I've created #120 to fix this. Would really appreciate it if we could merge and release the fix as the issue is creating broken builds without any warning for some people.
Note: The [\s\S]
solution above works in some cases, but will spill over to exported objects and functions.