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

esbuild sourcemap loses filename on web components #60

Open
steve-o opened this issue Sep 24, 2024 · 2 comments
Open

esbuild sourcemap loses filename on web components #60

steve-o opened this issue Sep 24, 2024 · 2 comments

Comments

@steve-o
Copy link

steve-o commented Sep 24, 2024

With esbuild 0.23.1 and 0.24.0, when the esbuild-plugin-minify-html-literals is enabled, if a component is not explicitly imported by name then the sourcemap output is absent the filename.

Example:

... "../../src/frontend/components", "../../src/frontend/components", "../../src/frontend/components", "../../src/frontend/components", ...

With the following esbuild script:

import esbuild from 'esbuild';
import { minifyHTMLLiteralsPlugin } from 'esbuild-plugin-minify-html-literals';
import { compressPlugin } from '@liber-ufpe/esbuild-plugin-compress';

const commonOptions = {
    	bundle: true,
    	sourcemap: true,
    	logLevel: 'info',
};

const compress = compressPlugin({
	gzip: false,
	brotli: true,
	deflate: false,
});

await esbuild.build({
	minify: true,
	splitting: true,
	entryPoints: ['src/frontend/index.ts'],
	outdir: 'dist/frontend',
	format: 'esm',
	platform: 'browser',
	target: 'esnext',
	tsconfig: 'src/frontend/tsconfig.json',
	metafile: true,
	plugins: [
		minifyHTMLLiteralsPlugin(),
		compress,
	],
	...commonOptions,
})

With the index.ts basically re-exporting components,

export * from './components/boris-plaintext-input.js';
export * from './components/boris-poster.js';
export * from './components/boris-progress.js';
export * from './components/boris-publish-dialog.js';

With components looking similar to:

import { LitElement, css, html } from 'lit';
import { customElement, property, query } from 'lit/decorators.js';

@customElement('boris-plaintext-input')
export class BorisPlaintextInputElement extends LitElement {
}
@bennypowers
Copy link
Owner

That's quite specific 😁

Perhaps the issue is here?

const contents = result && `${result.code}\n//# sourceMappingURL=${result.map?.toUrl()}`;

Happy to take a PR with tests

@steve-o
Copy link
Author

steve-o commented Sep 24, 2024

Looks like the following is more conducive:

const sourcemap = result && result.map?.toUrl();
const contents = result && (sourcemap.startsWith('data:') ? result.code : `${result.code}
//# sourceMappingURL=${result.map?.toUrl()}`);

i.e. the sourcemap URL is presenting as a data URI and should not be linked.

data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLm1hcCIsInNvdXJjZXMiOltudW...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants