-
Notifications
You must be signed in to change notification settings - Fork 4.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
Modify wp-scripts to transpile node_modules #18798
Modify wp-scripts to transpile node_modules #18798
Conversation
Transpiling Few areas where that could be improved are:
|
How does CRA manage to avoid these issues without offering any configuration? If we need to, how about an approach like:
{
"wp-scripts": {
"build": {
"transpile-dependencies": [ "mapbox-gl" ]
}
}
}
Can you please review my changes 🙏 |
That's a good question and I don't know the answer 🙂 Looking at CRA sources, it seems they transpile everything in |
Have you (or could you) measure the impact this would have on build time? This concerns me for a few reasons, including:
There's a lot to catch up on in some of the related discussions @jsnajdr mentions. What I'd prefer most is:
|
@aduth For a very simple app that I created purely for testing purposes, the increase in build time is <10% on both empty and primed caches. Are you able to recommend a larger repository that uses Inconclusive results from an overly simple appBefore:
After:
|
@jsnajdr I don't have any stats. We must transpile to keep using some libraries and support IE11 / ES5 browsers, so how much slower it makes the build isn't really relevant. |
That said, I would assume that transpiling everything would be a significant slowdown, and that's why we currently have an explicit whitelist system, right? |
We've been pretty happy with a whitelist and a post-build validation step that verifies that we've caught everything that would fail a syntax check. First-party dependencies are a pretty easy to fix problem, it's the transitive stuff that will bite you. When you have a library that's ES5 but then updates to use |
@sgomes It wasn't that slow from what I recall. The blocker was that it wasn't entirely safe. |
To be honest, I thought we were using it in this project, which was my primary concern. I think a project the scale of Gutenberg (or in fact an intention to use this for Gutenberg) is a fair target, though. |
Regarding the impact on performance, I've copy/pasted the webpack rule into the main BeforeEmpty cache
Primed cache
AfterEmpty cache
Primed cache
Regarding the concern around modules not transpiling correctly, I've implemented the |
@aduth and @jameslnewell – do we still want to have this change applied? |
As far as I know, there's not a specific need for it at the moment, since |
Description
I've modified
wp-scripts
to transpile modules imported fromnode_modules
because a significant number of packages are transpiling down to the current JS standard instead of transpiling down to ES5. Importing these packages into an application built withwp-scripts
breaks older browsers which are still supported by WordPress e.g. IE11.This problem arises with many of
sindresorhus
' packages where he primarily targets NodeJS as encountered here.Create React App and Parcel have already implemented similar solutions.
Aside: There appears to be a broader effort to solve the problems around dependencies and their targeted runtimes that doesn't affect bundle size like transpiling down to the lowest common denominator (ES5) does.
How has this been tested?
I created a new
wp-scripts
app, importedhex-rgb
and checked the build output forlet
andconst
.Screenshots
Types of changes
No external changes.
Checklist: