For example, if I have a JavaScript cell in a Markdown file docs/index.md:
```js
import {foo, bar} from "./foo.js";
```
And then foo.js imports bar.js using an absolute path (beginning with /):
export const foo = "foo";
export {bar} from "/bar.js";
Then foo.js will need to be rewritten during build and preview to append /_file in front of /bar.js to fix the import path (since imported modules are treated as file attachments and served from /_file). Note that only absolute paths need to be rewritten; relative paths that start with ./ or ../ are fine.
Since we’re transforming (rewriting) the ES module to fix the import path, we might also consider serving imported local modules from a different path, such as /_module instead of /_file. That way we could guarantee that anything in /_file is preserved as-is, and we could consider additional rewrites for imported local ES modules, such as minification, bundling, and transpiling TypeScript.
For example, if I have a JavaScript cell in a Markdown file docs/index.md:
And then foo.js imports bar.js using an absolute path (beginning with
/):Then foo.js will need to be rewritten during build and preview to append
/_filein front of/bar.jsto fix the import path (since imported modules are treated as file attachments and served from/_file). Note that only absolute paths need to be rewritten; relative paths that start with./or../are fine.Since we’re transforming (rewriting) the ES module to fix the import path, we might also consider serving imported local modules from a different path, such as
/_moduleinstead of/_file. That way we could guarantee that anything in/_fileis preserved as-is, and we could consider additional rewrites for imported local ES modules, such as minification, bundling, and transpiling TypeScript.