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 fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {csvLoader} from 'inline-schema/csv-loader/esbuild';
|
import {csvLoader} from 'inline-schema/csv-loader/esbuild';
|
||||||
|
import type { Plugin } from 'esbuild';
|
||||||
|
|
||||||
const srcDir = fileURLToPath(new URL('./src', import.meta.url));
|
const srcDir = fileURLToPath(new URL('./src', import.meta.url));
|
||||||
const samplesDir = fileURLToPath(new URL('./src/samples', 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();
|
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({
|
export default defineConfig({
|
||||||
entry: samplesEntries,
|
entry: samplesEntries,
|
||||||
format: ['esm'],
|
format: ['esm'],
|
||||||
|
|
@ -38,10 +65,5 @@ export default defineConfig({
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
outDir: 'dist/samples',
|
outDir: 'dist/samples',
|
||||||
external: ['@preact/signals-core', 'mutative', 'inline-schema', 'boardgame-core'],
|
external: ['@preact/signals-core', 'mutative', 'inline-schema', 'boardgame-core'],
|
||||||
esbuildPlugins: [csvLoader()],
|
esbuildPlugins: [csvLoader(), rewriteBoardgameImports()],
|
||||||
esbuildOptions(options) {
|
|
||||||
options.alias = {
|
|
||||||
'@': srcDir,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue