-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[tsc] Ensure shared TypeScript modules are compiled to be compatible with Node and Webpack #32578
Conversation
Pinging @elastic/kibana-operations |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
The reason we need to use esm for the browser typescript is so we have esm features like mutable export bindings, but if you find a way around that I'd be happy to have this.
💚 Build Succeeded |
@spalger That's what I ended up realizing. I've modified this now to make it build browser TS first, and then server TS. This "works" with the current modules that are shared since the shared modules will be in CommonJS format (compiled by the serve build) and we're actually only import type information right now across to the client-side code. I think this solution is fine for the time being, because it is temporary. We plan to move to immutable bundles with no JS or TS compilation happening at all in production builds. If we wanted to a slightly better intermediate step, we could ship TS source files and the TypeScript compiler with ts-loader to be able to generate ES6 Modules when re-optimizing in production. |
Yeah, that sounds reasonable to me. Maybe once we have babel7 we could compile these files to |
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.
LGTM
Can you update the comment before merging with details about the drawback to this that you and @spalger discussed in the PR comments? Right now it just explains why we do it but not what the consequence of this is, even if it is only temporary.
Summary
This modifies the TypeScript build step order to ensure that any shared code is built to a format that both Node and Webpack can use. I did this by making the browser build complete before the server build so that shared code is built into CommonJS modules.
This "works" with the current modules that are shared since the shared modules will be in CommonJS format (compiled by the serve build) and we're actually only import type information right now across to the client-side code.
I think this solution is fine for the time being, because it is temporary. We plan to move to immutable bundles with no JS or TS compilation happening at all in production builds. Other options before we get to immutable bundles:
.browser.js
and prefer that when importing via Webpack.From #32567