-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat(webpack): introduce experimental esbuild transpilation #1632
Conversation
9ed63c5
to
3bb64c4
Compare
0d7efac
to
d75c5d7
Compare
Jest is also mostly working now. We have one Flow test that isn't working, which is fine I guess and there seems to be another import syntax that is hard to match via regex. Not sure what we do about that. The syntax I am talking about:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the import component loader: couldn't we leverage acorn when we find ocurrences of importComponent(
in the code and then basically replicating thte respective babel loader code?
Or we check whether there's a second parameter passed into importComponent
, and if there is, issue an error telling the user, that Hops's esbuild-feature currently only supports default exports in importComponent
. 🤷♂️
Btw, in ESBuild there are four different loaders: I think I should align that to the webpack loader as well, but that would require everyone who wants to use this esbuild feature to possibly fix their file extensions. |
I think it would be fine to introduce this requirement for an experimental feature coming with a major update. But if we want to go further down the esbuild road, we'll eventually have to introduce that requirement to everybody. I personally think that's appropriate. Do we all agree on that? |
I took a stab at that a few days ago, unfortunately, the webpack parser APIs are not so easy and also pretty much not documented. I guess it'd be easier to continue with the RegExp based solution if we want to finish it in time for Hops 14.
I'd prefer, if we can handle named imports, I'll take a look at the regex, so see if I can figure out a way. |
Another thing to keep in mind: There seems to be some incompatibility when using esbuild artifacts in webpack: evanw/esbuild#758 (see also PR 2855 in crate). We should evaluate if that is also the case here. |
|
||
module.exports = { | ||
process(content, filename, config, opts) { | ||
content = content.replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another idea: We could do a regex test for importComponent
and if we find it, we then load acorn / babel / whatever to do the actual AST transform. That would be safer, because a regex replace alone can't catch things like import { importComponent as importC } from 'hops'
or it might replace the wrong thing (if for some reason a file contains a function call to importComponent()
from a different package.
a3ffe94
to
d2cad6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is missing. For testing you need to set USE_EXPERIMENTAL_ESBUILD
and otherwise you use --experimental-esbuild
or the env var. It would be good to have that documented ;)
|
||
if (experimentalEsbuild) { | ||
console.warn( | ||
'The experimental esbuild transpilation does not support styled components yet!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't support it for SSR, right? But it would still give useful output in dev mode?
Maybe change this warning a bit, to indicate that it can still be used in dev mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't really looked into it so I'm not sure yet what works and what doesn't.
const { | ||
include, | ||
exclude, | ||
use: [{ loader, options }, ...loaders], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use: [{ loader, options }, ...loaders], | |
use: [{ loader: esbuildLoader, options }, ...loaders], |
To make it a little more clear what's going on here.
@@ -0,0 +1,32 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also run a jest test in this integration test, to demonstrate how it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if that command-line flag has an "experimental" in its name I wonder: Shouldn't Hops print a warning/info saying that
- it is experimental
- some things may not work as expected (apart from styled components)
- and that a production build is created differently
bors merge |
Build succeeded:
|
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
2070: Fix `importComponent` r=ZauberNerd a=ZauberNerd Ref: #1632, #1976 Todo: - [x] What happens if we import the same file from different files? I suspect our babel plugin will generate different chunk names which should in fact not be different. So maybe our hash should not include the filepath of the importing component but only the filepath of the imported component. - seems to create separate entries in the `namedChunkGroups` which point to the same asset. <details> <summary>Bors merge bot cheat sheet</summary> We are using [bors-ng](https://github.com/bors-ng/bors-ng) to automate merging of our pull requests. The following table provides a summary of commands that are available to reviewers (members of this repository with push access) and delegates (in case of `bors delegate+` or `bors delegate=[list]`). | Syntax | Description | | --- | --- | | bors merge | Run the test suite and push to master if it passes. Short for "reviewed: looks good." | | bors merge- | Cancel an r+, r=, merge, or merge= | | bors try | Run the test suite without pushing to master. | | bors try- | Cancel a try | | bors delegate+ | Allow the pull request author to merge their changes. | | bors delegate=[list] | Allow the listed users to r+ this pull request's changes. | | bors retry | Run the previous command a second time. | This is a short collection of opinionated commands. For a full list of the commands read the [bors reference](https://bors.tech/documentation/). </details> Co-authored-by: Björn Brauer <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
In case the `--experimental-esbuild` mode is used, we have a small webpack loader to handle the `importComponent` transformation. This had been introduced in #1632 to be a quick & dirty regex based replacer. With this commit we now have a webpack loader that has a fast-exit path in case `importComponent` is not used. Otherwise it will transpile the source code using the proper babel plugin. Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Philipp Hinrichsen <[email protected]> Co-authored-by: Robert Kowalski <[email protected]>
To test this just add
esbuild
andesbuild-loader
as dependencies tohops-template-redux
.Memory consumption also goes down from ~340MB to ~240MB.