Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sourcemap for watch was different to build #4229

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 33 additions & 54 deletions packages/esbuild-plugins/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,95 +39,74 @@ export const isDevelopment = argv.mode === "development";
export const isProduction = !isDevelopment;
export const isWatch = argv.watch;

export function build(config: BuildOptions) {
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Start: ", config.entryPoints[0], config.outfile);
}
return esbuild.build({
sourcemap: "linked",
async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions): Promise<void> {

const ctx = await esbuild.context({
entryPoints: [input],
format: format as Format,
bundle: true,
minify: isProduction,
sourcemap: isDevelopment,
external,
...config,
plugins: [
...(isWatch ? [rebuildLogger(config)] : []),
...(config.plugins ?? []),
sfxWasm()
]
}).finally(() => {
});

if (isWatch) {
await ctx.watch();
} else {
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Start: ", config.entryPoints[0], config.outfile);
}
await ctx.rebuild();
await ctx.dispose();
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Stop: ", config.entryPoints[0], config.outfile);
}
});
}

export async function watch(config: BuildOptions) {
await build(config);
return esbuild.context({
sourcemap: "external",
...config,
plugins: [
...(config.plugins ?? []),
rebuildLogger(config),
sfxWasm()
]
}).then(ctx => {
return ctx.watch();
});
}

export function buildWatch(config: BuildOptions) {
return isWatch ? watch(config) : build(config);
}
}

export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
platform: "browser",
target: "es2022",
format: format as Format,
globalName,
bundle: true,
minify: isProduction,
external,
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
});
}

export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
return Promise.all([
browserTpl(input, output, "esm", globalName, libraryName, external),
browserTpl(input, output, "umd", globalName, libraryName, external)
]);
}

export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
platform: "node",
target: "node20",
format: format as Format,
bundle: true,
minify: isProduction,
external
target: "node20"
});
}

export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
platform: "neutral",
target: "es2022",
format: format as Format,
globalName,
bundle: true,
minify: isProduction,
external,
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
});
}

export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
return Promise.all([
browserTpl(input, output, "esm", globalName, libraryName, external),
browserTpl(input, output, "umd", globalName, libraryName, external)
]);
}

export function nodeBoth(input: string, output: string, external: string[] = []) {
return Promise.all([
nodeTpl(input, output, "esm", external),
Expand Down
Loading