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

Replace webpack with esbuild #5086

Closed
wants to merge 8 commits into from
Closed

Replace webpack with esbuild #5086

wants to merge 8 commits into from

Conversation

fregante
Copy link
Member

@fregante fregante commented Nov 19, 2021

Copy link
Member Author

@fregante fregante left a comment

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 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
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
Member Author

Blocked by

🤷‍♂️

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

hyrious commented Nov 20, 2021

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
Member Author

Thank you!

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