50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import { build } from 'vite';
|
|
|
|
const seen = new Map();
|
|
|
|
function tracePlugin() {
|
|
return {
|
|
name: 'trace-jiti-importer',
|
|
async resolveId(source, importer, options) {
|
|
if (source.includes('jiti') || importer?.includes('jiti')) {
|
|
console.log('[resolve]', { source, importer });
|
|
}
|
|
const resolved = await this.resolve(source, importer, {
|
|
...options,
|
|
skipSelf: true,
|
|
});
|
|
if (resolved?.id?.includes('jiti') || source.includes('jiti')) {
|
|
console.log('[resolved]', { source, importer, resolved: resolved?.id });
|
|
}
|
|
return resolved;
|
|
},
|
|
load(id) {
|
|
if (id.includes('jiti')) {
|
|
console.log('[load]', id);
|
|
}
|
|
return null;
|
|
},
|
|
moduleParsed(info) {
|
|
if (info.id.includes('jiti')) {
|
|
console.log('[moduleParsed]', info.id);
|
|
console.log(
|
|
'[importers]',
|
|
Array.from(seen.entries()).filter(([, imports]) =>
|
|
imports.some((item) => item.includes('jiti')),
|
|
),
|
|
);
|
|
}
|
|
seen.set(info.id, Array.from(info.importedIds));
|
|
},
|
|
};
|
|
}
|
|
|
|
await build({
|
|
configFile: './apps/web-ele/vite.config.mts',
|
|
mode: 'production',
|
|
plugins: [tracePlugin()],
|
|
build: {
|
|
write: false,
|
|
},
|
|
});
|