47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { build } from 'vite';
|
|
|
|
function tracePlugin() {
|
|
const importers = [];
|
|
return {
|
|
name: 'trace-jiti-importer',
|
|
async resolveId(source, importer, options) {
|
|
if (source.includes('jiti') || importer?.includes('jiti')) {
|
|
console.log('[resolve]', JSON.stringify({ source, importer }));
|
|
}
|
|
const resolved = await this.resolve(source, importer, {
|
|
...options,
|
|
skipSelf: true,
|
|
});
|
|
if (resolved?.id?.includes('jiti') || source.includes('jiti')) {
|
|
console.log(
|
|
'[resolved]',
|
|
JSON.stringify({ source, importer, resolved: resolved?.id }),
|
|
);
|
|
}
|
|
return resolved;
|
|
},
|
|
moduleParsed(info) {
|
|
if (info.importedIds.some((id) => id.includes('jiti'))) {
|
|
importers.push({
|
|
id: info.id,
|
|
importedIds: info.importedIds.filter((id) => id.includes('jiti')),
|
|
});
|
|
console.log('[imports-jiti]', JSON.stringify(importers.at(-1)));
|
|
}
|
|
if (info.id.includes('jiti')) {
|
|
console.log('[module-jiti]', info.id);
|
|
console.log('[jiti-importers]', JSON.stringify(importers, null, 2));
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
await build({
|
|
configFile: './vite.config.mts',
|
|
mode: 'production',
|
|
plugins: [tracePlugin()],
|
|
build: {
|
|
write: false,
|
|
},
|
|
});
|