-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Framework: Remove packages build from build, dev scripts #15226
Conversation
This change disables also source maps support: gutenberg/packages/scripts/config/webpack.config.js Lines 81 to 85 in 59097fe
|
That's unfortunate. In which case, we might need the "rethink" I'd described at #14560 (comment) sooner than later. Some initial ideas here include:
|
@nosolosw any thoughts on this issue? |
I've been reading a bit more about the relationship between
|
@nosolosw, in fact you need only |
That's an interesting proposal. I think it could work. The main downside I see is that when someone runs |
Actually, I don't think anything else needs to change:
|
59097fe
to
ba0ef74
Compare
Well, the failing build would at least demonstrate why the packages build would be necessary, or at least specifically for packages upon which the Webpack configuration itself depends:
I guess it'd worked for me locally because I'd already had a built copy available. One option might be to rewrite this Webpack plugin as plain CommonJS. |
There were two packages which needed to be adapted to CommonJS:
Puzzlingly, both of these were already implemented as CommonJS ([1], [2]), but with folder structures and This wasn't the only problem, unfortunately. Since Webpack will interpret the I'm not sure I'm as comfortable with this approach as in the original proposal, since:
It is quite fast though: I see |
From the failing build, there are more things to consider:
|
I think one of the main reasons to run babel there was to generate the "messages" in prod as these are not generated by the packages build process. |
Can you explain more what you mean by this? I'm not sure what "messages" you're referring to. |
@aduth I was referring to the |
@youknowriad Correct, we no longer use |
These are extraneous tasks which should probably be done separately anyways, which I've proposed:
|
@gziolo you can using aliases, that said, I'm not particularly attached to the playground using parcel, it just seemed easier to setup that way. |
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 think I have a preference for this option as it's strictly equivalent to what Core does and I don't think going throught the files once more is too time consuming if we drop babel.
This PR proposes the alternative approach which seems to be much faster. However, the downside is that we no longer will be testing whether the generated distribution version of packages works as expected. I think it's a good trade-off for development
to use sources directly. How about we mix two approaches and use the version optimized for speed with npm start
and the version optimized for stability with npm run build
?
Aside:
- we use sources of all packages with unit tests
- we use build folders of all packages with code that maintains e2e tests
We should take some strategic decisions to align the approach after we land this PR. I would be fine in having the approach to be optimized for speed thus using sources everywhere but having a flag which would allow using packages prepared for npm on demand to run with one of the jobs on Travis - maybe it's fine to do it on Travis only?
Aside 2:
$ time npm run build:packages
real 0m29.945s
user 0m36.459s
sys 0m3.108s
package.json
Outdated
@@ -157,13 +157,13 @@ | |||
"clean:packages": "rimraf ./packages/*/build ./packages/*/build-module ./packages/*/build-style ./packages/*/node_modules", | |||
"prebuild:packages": "npm run clean:packages && lerna run build", | |||
"build:packages": "node ./bin/packages/build.js", | |||
"build": "npm run build:packages && wp-scripts build", | |||
"build": "wp-scripts build", |
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.
At the moment lerna run build
is needed only for one package which isn't part of the application so it's fine as is.
A thought: Rather than expecting a project to import and manipulate the default Webpack configuration object, could we implement the default configuration so that it responds to flags passed to There might need to be some consideration on how we name these flags, depending on how much we want to expose internal implementation detail of the build. Considering that Babel is integrated pretty tightly into the build tool (local Babel configurations are detected), this flag seems reasonable enough to me in its current form. |
3d851b9
to
3b7201e
Compare
In the rebase, I revert back to the original proposal to omit Babel from the Webpack build, using a new fla as in my previous comment #15226 (comment) . As discussed, there are some other considerations for how we might want to take this, but I think this is a good middle-ground compromise for a resolution to the immediate problem that we run Babel twice in both |
package.json
Outdated
@@ -156,7 +156,7 @@ | |||
"clean:packages": "rimraf ./packages/*/build ./packages/*/build-module ./packages/*/build-style ./packages/*/node_modules", | |||
"prebuild:packages": "npm run clean:packages && lerna run build", | |||
"build:packages": "node ./bin/packages/build.js", | |||
"build": "npm run build:packages && wp-scripts build", | |||
"build": "npm run build:packages && wp-scripts build --no-babel", |
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 personally don't like the no-babel
option. I wonder if we're not doing ourselves a disservice in assuming that using wp-scripts
is good as we're proofing it while in reality, we tweak its config in a way that makes it different from what the users of wp-scripts
do. I'd personally rather just embrace the fact that Gutenberg is a special case here and use webpack directly.
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.
Using webpack directly won't solve the issue fully. The shared webpack config which by default has this Babel integration built-in is something that needs to be tweaked.
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 think it's important to understand why we're using webpack at the root level of Gutenberg to understand the issue and what is the "common" webpack config Gutenberg setup has with wp-scripts setup.
The answer is simple, there's nothing really important to share between these two webpack configs aside the DependencyExtractionWebpackPlugin
plugin for me. Is this sufficient to try to include checks in the common config instead of just duplicating the 4/5 lines that are common?
@youknowriad What do you envision as the purpose of |
@aduth for me, ideally the users don't touch the babel config at all, it's not even an option. Its main target are plugin/theme developpers that want a tool to build their plugins with sane defaults but don't want to understand/invest in the config files of all the build tools. That doesn't mean they shouldn't offer any config, but I see these as more "user-facing" options. Some of these options could be:
but not something related to the syntax itself |
@youknowriad It's still not very clear to me. You're suggesting that enabling ES2015 transpilation is not something we should be including as a feature of the If it is the latter, I have no qualms against alternative naming for an option. Something like |
@aduth In my mind both :). I think the tool should offer sane defaults and plugin authors shouldn't think about whether they enable ES6 or anything. That said, I don't want to block that PR because of that. I'd prefer to just rely on webpack and custom config at the root level but admittedly, we already support custom configs in the tool (that goes against what I think the goal of the tool should be), so it's not going to be worst with this new option :) |
I don't feel compelled to rush this in. Or at least, I want to better understand what our expectations are for † I have opinions on this as well, and I tend to agree with earlier points of dogfooding, but I feel this is being a distraction in the conversation. |
3b7201e
to
eb309dc
Compare
Okay, I relent. The latest rebase will just avoid extending the default configuration. As previously noted, there's not a whole lot to reimplement to preserve the existing behavior ( I think this would be reasonable to address the immediate issue of the Babel double-run and, if we choose to, sort out an alternative solution which supports this, the goals of |
@@ -134,5 +147,7 @@ module.exports = { | |||
}, | |||
}, | |||
] ), | |||
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ), |
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.
There are two things that are removed by this change. I believe the webpack bundle analyzer and the live reload config. I'm not sure if people find these useful or not but I thought I'd mention.
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.
There are two things that are removed by this change. I believe the webpack bundle analyzer and the live reload config. I'm not sure if people find these useful or not but I thought I'd mention.
Oof. Well, I can go conservative and leave the behavior unaffected, with the downsides of (a) more duplication and (b) more changes to package.json
and package-lock.json
or (b) just drop them. I've personally not made use of them (though in the former case, I have done bundle analysis by just calling webpack --stats
directly).
Not sure yet how I want to proceed.
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'm personally fine with just removing those as not much used but it could be done separately and I think we can move forward here.
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'm personally fine with just removing those as not much used but it could be done separately and I think we can move forward here.
I'll commit to reintroducing it if anyone mentions it.
Previously: #15219
Related: #14560
This pull request seeks to update the Gutenberg-specific Webpack configuration to avoid running Babel as part of the Webpack build. As described at #15219 (comment), the files processed by Webpack are already transpiled by Babel as a step immediately prior. Including
babel-loader
is therefore redundant, wasted effort.With this change, I'd measured approximately a 57% decrease in the time it takes to run
npx wp-scripts build
(~16.7s to 7.1s, measured usingtime
).Testing Instructions:
git clean -fdx
(Warning: This will forcefully remove any uncommitted files)npm run build
build/*/*.js
and inpackages/*/build/*.js
are transpiled as expected by Babel (e.g. no ES2015 or JSX)