Skip to content

Replace webpack with esbuild - #5086

Closed
fregante wants to merge 8 commits into
mainfrom
esbuild
Closed

fregante wants to merge 8 commits into
mainfrom
esbuild

Conversation

@fregante

@fregante fregante commented Nov 19, 2021 •

Copy link
Copy Markdown
Member

@fregante fregante left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested

Screen Shot 2

Comment thread build/esbuild.ts
Comment on lines +1 to +7
import {createRequire} from 'node:module';

import esbuild from 'esbuild';

import {getFeatures, getFeaturesMeta} from './readme-parser.js';

const {resolve: resolvePackage} = createRequire(import.meta.url);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space generously gifted by our lint rules 😌

@fregante

Copy link
Copy Markdown
Member Author

Blocked by

🤷‍♂️

@fregante fregante closed this Nov 19, 2021
@fregante
fregante deleted the esbuild branch November 19, 2021 13:52
@hyrious

hyrious commented Nov 20, 2021 •

Copy link
Copy Markdown

I'll give you 2 plugins to solve import.meta.url and the warning of typed-query-selector:

  • replace all import.meta.url to absolute path to the source file
  • load typed-query-selector by self, with empty content (so that esbuild won't look at the real package)
import {readFile} from 'node:fs/promises'
import {pathToFileURL} from 'node:url'

const importMeta: esbuild.Plugin = {
	name: 'Import Meta',
	setup(build) {
		build.onLoad({filter: /source.features.\S+\.tsx$/}, async args => {
			let contents = await readFile(args.path, 'utf8');
			contents = contents.replace(
				/\bimport\.meta\.url\b/g,
				JSON.stringify(pathToFileURL(args.path)),
			);
			return { contents, loader: 'default' }
		});
	},
};

const TypedQuerySelector: esbuild.Plugin = {
	name: 'typed-query-selector',
	setup(build) {
		build.onResolve({filter: /^typed-query-selector$/}, ({path}) => {
			return { path, namespace: 'typed-query-selector' };
		});
		build.onLoad({filter: /()/, namespace: 'typed-query-selector'}, (a) => {
			return { contents: '', loader: 'js' };
		});
	},
}

Note that it may not pass type checking, but you can know what it do.

@fregante

Copy link
Copy Markdown
Member Author

Thank you!

@fregante fregante mentioned this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants