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

STRWEB-4: Update webpack to version 5 #36

Merged
merged 7 commits into from
Nov 4, 2021
Merged

STRWEB-4: Update webpack to version 5 #36

merged 7 commits into from
Nov 4, 2021

Conversation

mkuklis
Copy link
Contributor

@mkuklis mkuklis commented Oct 11, 2021

https://issues.folio.org/browse/STRWEB-4

There are two corresponding PRs:

These will have to be merged after this PR is merged.

Notes:

The biggest struggle with the upgrade was related the way compilation hooks were changed. The hooks object became frozen in webpack 5 (https://webpack.js.org/blog/2020-10-10-webpack-5-release/#hook-object-frozen). The way stripes webpack plugins communicate and the StripesConfigPlugin had to be refactored to follow this new pattern.

I noticed a nice performance boost from both stripes build and stripes serve. For example platform-complete builds in half of the time compared to webpack 4. The initial stripes serve (the first time stripes serve is executed in a given folder) takes similar time to what we saw in webpack 4 but the following stripes serve is about 5x faster.

The best way to try it out before this work is merged is to checkout both stripes-webpack (STRWEB-4 branch) and stripes-cli (STCLI-187 branch) into a workspace together with a single ui module and add "webpack": "^5.58.1" to resolutions to make sure the correct version is being used (this may not be required).

"resolutions": {
  "webpack": "^5.58.1",
}

Webpack 5 should open the door to a few nice features:

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! So excited to see you just grabbed this sucker and went for it! 99% fine to me, but the login screen logo doesn’t load for me and I see

<img alt="..." src="[object Module]">

in the source vs

<img alt="..." src="/img/tenant-assets/opentown-libraries-logo.c96ff678691e1a345321b50941335d81.png">

from folio-snapshot. I see the same behavior whether in a workspace or platform build. Trying to compile a build to an output directory, I get

Module not found: Error: Can't resolve 'postcss-loader' in '/Users/zburke/temp/platform-core'

@JohnC-80, do you recall if there were any webpack-5 specific notes in the post-css work (#31) you did a few weeks ago that now come into play?

These are the only two glitches I've found so far. Nice work!

Edit: additional config details:

$ yarn --version
1.22.11
$ node --version
v16.10.0
platform-core(snapshot)*
$ npm --version
7.24.0
platform-core(snapshot)*
$ uname -a
Darwin LP-C02G8208ML85 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

@mkuklis
Copy link
Contributor Author

mkuklis commented Oct 13, 2021

Thanks for trying this out @zburke!

Would you mind sharing your workspace setup with me?

I will try to checkout stripes-cli#STCLI-187 and stripes-webpack#STRWEB-4 with a single ui module (maybe ui-users) in order to reproduce it.

Would that be enough?

@zburke
Copy link
Member

zburke commented Oct 13, 2021

@mkuklis, a straight clone of platform-core#snapshot (i.e. not a workspace) with the following resolutions shows both glitches:

  "@folio/stripes-cli": "folio-org/stripes-cli#STCLI-187",
  "@folio/stripes-webpack": "folio-org/stripes-webpack#STRWEB-4",

when serving via yarn local or building via yarn stripes build stripes.config.js.

@JohnC-80
Copy link
Contributor

Yeah, @mkuklis - Thank you for grabbing this bull by the horns. I'm very interested in what federated modules will ultimately be able to do for us.
Not gonna lie, I'm a little jealous of what you may have learned in this process.
I think we'll ultimately want to upgrade all of the loaders to their latest version that have probably shuffled off backwards compatibility with webpack v4...
postcss-loader, css-loader are on this 'definitely' list in my mind, happy to take on those upgrades.

There's been some weirdness with the branding icons in a workspace... I haven't had a chance to look into it yet. The wrong thing getting stringified/stringifying the object when it probably needs to use a key of the object (I suspect).

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@mkuklis
Copy link
Contributor Author

mkuklis commented Oct 14, 2021

Thank you for your feedback @JohnC-80. You are exactly right! I had to update postcss-loader. The version we had there was not compatible with webpack 5 anymore.

There is also css-loader which can be updated too but we will first need to migrate to asset modules https://webpack.js.org/guides/asset-modules before we can update css-loader. The current version works with webpack 5 so I'm going to leave it for now.

@zburke I would appreciate if you could give it another try with the most recent changes.

Oh I also had to upgrade eslint-config-stripes: folio-org/eslint-config-stripes#85

@mkuklis mkuklis requested a review from zburke October 14, 2021 03:20
Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With postcss v8 et al in place, images are now rendering correctly for me. Impossible to overstate how great this news is! LGTM! 🎉 🎉 🎉

@mkuklis
Copy link
Contributor Author

mkuklis commented Oct 14, 2021

Thank you for your help with testing this @zburke!

@mkuklis mkuklis requested a review from axelhunn October 14, 2021 15:00
@zburke
Copy link
Member

zburke commented Oct 14, 2021

Looks like maaaaybe some CSS stuff still isn't coming through correctly? Note also "form.restart is not a function". I have no idea where that's coming from 🤔 . **

Screen Shot 2021-10-14 at 11 54 32 AM (2)

My localhost is from a workspace with a platform and some stripes libs cloned (all UI apps are just pulled in via the platform). Compare with the folio-snapshot:

Screen Shot 2021-10-14 at 11 57 46 AM

** form.restart is a red-herring from an out-dated final-form dep; form.restart was added in v4.20.x but my build had only v4.18.x. Er, it's a red-herring WRT this PR, but that dep does need to get updated elsewhere.

@mkuklis
Copy link
Contributor Author

mkuklis commented Oct 14, 2021

Good find @zburke! I wonder what that form.restart is :)
I will take a look at these css issues.

@zburke
Copy link
Member

zburke commented Oct 14, 2021

@mkuklis, form.restart is a red-herring from an out-dated final-form dep. It's part of v4.20.x but my build had only v4.18.x. That's still a problem, but at least it's not a problem with this PR :)

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@mkuklis
Copy link
Contributor Author

mkuklis commented Oct 15, 2021

@zburke it looks like the issue with colors is related to https://github.com/postcss/postcss-color-function which has been deprecated. There is a PR there to update postcss version postcss/postcss-color-function#60 but it hasn't been merged. I pointed to that fork in stripes-webpack and it looks like that solved the problem for now.

There is also a newer lib (by the same author) which changes color function to color-mod:
https://github.com/csstools/postcss-color-mod-function

That lib is maintained and up to date but it looks like color-mod is also not part of the css spec anymore.

If we want to move to https://github.com/csstools/postcss-color-mod-function stripes-components would have to be updated to use color-mod() instead of color().

There are couple places where color() is currently used in stripes-components:

./lib/Card/Card.css
./lib/variables.css
./lib/Datepicker/Calendar.css
./lib/Callout/Callout.css
./lib/Button/Button.css
./lib/sharedStyles/form.css

I think since this was removed from the css spec perhaps a better alternative would be to refactor these to not use color() or color-mod() at all. I will let @JohnC-80 decide what to do here.

For now I'm leaving postcss-color-function (from the fork) so we can move forward with the webpack upgrade.

@zburke thanks again for catching this!

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

package.json Outdated
"postcss-url": "^8.0.0",
"postcss": "^8.3.9",
"postcss-calc": "^8.0.0",
"postcss-color-function": "onigoetz/postcss-color-function",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'm leaving postcss-color-function (from the fork) so we can move forward with the webpack upgrade.

Man, it feels like there just aren't good options here. We have some old (now incompatible) things that are unmaintained/deprecated but actually published, and we have some new forks that provide compatibility but haven't ever been formally published. Using a GitHub fork is a bit nerve-wracking. It's relatively hard to unpublish something from NPM, but it's super easy to remove a repository from GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is just a temporary solution until stripes-components is cleaned up. If you are worry about the fork we can fork it too for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I agree. I think the best would be to take care of the color right in stripes-components. Then we could remove postcss-color-function completely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkuklis, shall I write up an STCOM ticket (and corresponding STRWEB ticket) for this to make sure it gets handled for Lotus/R1-2022? @JohnC-80, do you foresee any reason to believe it would be a problem getting such work into Louts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zburke that sounds good to me. I cloned postcss-color-function to folio-org just in case the other repo disappears :).

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@id-jenkins
Copy link

yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@ryandberger ryandberger merged commit ac40b57 into master Nov 4, 2021
mkuklis added a commit that referenced this pull request Nov 5, 2021
This reverts commit ac40b57, reversing
changes made to b0068bd.
mkuklis added a commit that referenced this pull request Nov 5, 2021
* Revert "STRWEB-4 add crypto-browserify depenency to polyfill crypto in axe test runs (#37)"

This reverts commit ec148a4.

* Revert "Merge pull request #36 from folio-org/STRWEB-4"

This reverts commit ac40b57, reversing
changes made to b0068bd.
@zburke zburke deleted the STRWEB-4 branch January 21, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants