OverlayFS-like resolver for Rollup.
yarn add -D @anireact/rollup-plugin-rediretory
npm install --save-dev @anireact/rollup-plugin-rediretory
import rediretory from '@anireact/rollup-plugin-rediretory';
export default {
plugins: [
rediretory({
root: process.cwd(),
mappings: {
// When a file in `<root>/transpiled` imports something,
// and resolution fails, fall back to `<root>/src`:
transpiled: 'src',
// When a file in `<root>/src` imports something,
// and resolution fails, fall back to `<root>/generated`:
src: 'generated',
},
}),
],
};
root
(default:process.cwd()
) — the project root directory.mappings
— a record of key-value directory mappings; both keys and values are relative toroot
.
Let’s consider a project, that has:
- JS and CSS files in
/src
. - TS files from
/src
, transpiled withtsc
to/tmp
.
We don’t want to copy everything from /src
to /tmp
, so if /src/main.mts
transpiled to /tmp/main.mts
imports ./styles.css
, the resolution will fail,
because ./styles.css
cannot be resolved in /tmp
. To solve this, we could
just tell Rollup to check /src
when resolving files from /tmp
— if the
original resolution fails.
If you have any issues, feel free to fork this plugin, or contact me on Telegram https://t.me/miyaokamarina.
MIT © 2023 Yuri Zemskov