My workspace looks like this:
├─dist
│ └─index.mjs
└─src
└─utils
└─index.ts
I use import.meta.url in /src/utils/index.ts like this:
const __path_src_root = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../',
);
const __path_cache = path.resolve(
__path_src_root,
'../node_modules/.cache/@setup',
);
After packaging, import.meta.url will change due to directory changes, breaking the __path_cache. It changes from /path/to/cli/node_modules/.cache/@setup to /path/to/node_modules/.cache/@setup.
Is there a way to resolve this?
I don't want to use env var like process.env.prod ? ... : ...
By the way, I use rollup to pack my code and tried to find plugin to solve it but couldn't find anything.