refactor: externalize imports
This commit is contained in:
parent
91c993b223
commit
98a12b9266
|
|
@ -3,6 +3,7 @@ import { fileURLToPath } from 'url';
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {csvLoader} from 'inline-schema/csv-loader/esbuild';
|
||||
import type { Plugin } from 'esbuild';
|
||||
|
||||
const srcDir = fileURLToPath(new URL('./src', import.meta.url));
|
||||
const samplesDir = fileURLToPath(new URL('./src/samples', import.meta.url));
|
||||
|
|
@ -30,6 +31,32 @@ function getSamplesEntries(): Record<string, string> {
|
|||
|
||||
const samplesEntries = getSamplesEntries();
|
||||
|
||||
/**
|
||||
* Plugin to rewrite @/core/* and @/utils/* imports to use 'boardgame-core'
|
||||
*/
|
||||
function rewriteBoardgameImports(): Plugin {
|
||||
return {
|
||||
name: 'rewrite-boardgame-imports',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^@\/(core|utils)\// }, args => {
|
||||
// Mark these as external and rewrite to 'boardgame-core'
|
||||
return {
|
||||
path: 'boardgame-core',
|
||||
external: true,
|
||||
};
|
||||
});
|
||||
|
||||
// Also handle @/index imports
|
||||
build.onResolve({ filter: /^@\/index$/ }, args => {
|
||||
return {
|
||||
path: 'boardgame-core',
|
||||
external: true,
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
entry: samplesEntries,
|
||||
format: ['esm'],
|
||||
|
|
@ -38,10 +65,5 @@ export default defineConfig({
|
|||
sourcemap: true,
|
||||
outDir: 'dist/samples',
|
||||
external: ['@preact/signals-core', 'mutative', 'inline-schema', 'boardgame-core'],
|
||||
esbuildPlugins: [csvLoader()],
|
||||
esbuildOptions(options) {
|
||||
options.alias = {
|
||||
'@': srcDir,
|
||||
};
|
||||
},
|
||||
esbuildPlugins: [csvLoader(), rewriteBoardgameImports()],
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue