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

feat(storybook): update sass loaders and use dart-sass #8228

Merged

Conversation

joshblack
Copy link
Contributor

@joshblack joshblack commented Mar 30, 2021

Update storybook config and loader dependencies to use dart-sass, enables use of sass modules in the storybook.

Changelog

Changed

  • update and reconfigure sass loaders for storybook

Removed

  • remove fast-sass-loader

Testing / Reviewing

The deploy preview should show the CSS Grid styles in the Auto Columns story as an example. Once approved I can remove the example story.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2021

DCO Assistant Lite bot All contributors have signed the DCO.

@joshblack
Copy link
Contributor Author

I have read the DCO document and I hereby sign the DCO.

@netlify
Copy link

netlify bot commented Mar 30, 2021

Deploy preview for carbon-elements ready!

Built with commit 2619e8b

https://deploy-preview-8228--carbon-elements.netlify.app

@netlify
Copy link

netlify bot commented Mar 30, 2021

Deploy preview for carbon-components-react ready!

Built without sensitive environment variables with commit 2619e8b

https://deploy-preview-8228--carbon-components-react.netlify.app

},
sourceMap: true,
},
};

const fastSassLoader = {
loader: 'fast-sass-loader',
loader: require.resolve('fast-sass-loader'),
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be using and recommending fast-sass-loader as we begin to embrace sass modules. It doesn't support @use, but beyond that, the ways it achieves a faster compile time don't seem to match with how @use is intended to work with @import and vice-versa.

In addition to namespacing, there are a few important differences between @use and @import:

  • @use only executes a stylesheet and includes its CSS once, no matter how many times that stylesheet is used.
  • @use only makes names available in the current stylesheet, as opposed to globally.
  • Members whose names begin with - or _ are private to the current stylesheet with @use.
  • If a stylesheet includes @extend, that extension is only applied to stylesheets it imports, not stylesheets that import it.

fast-sass-loader uses regex to grab all the imports and hoist them all into one file. It then caches the result to avoid recompiling. I tried patching it locally to modify the regex to include @use, but when it passes the result off to sass it still can't resolve files, even the built in modules fail. If the resolution problem was fixed, I don't think we'd see appropriate namespacing control as everything would essentially be global. I suspect it would also impact usages of @forward.

To my eye, @use sort of turns the value proposition of the library upside down. Especially after @joshblack saw compile times significantly improve with sass modules, #7525

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

I pushed a commit to remove fast-sass-loader and use sass-loader in both dev and prod. I tested a fresh storybook dev (yarn start) and see an increase in build time:

fast-sass-loader sass-loader
42s for manager 51s for manager
53s for preview 1min 46s for preview

Recompile time should be less. I also think we'll see a decrease when using sass modules? Also it might help if we imported component-level modules per *-story.js file instead of including all styles globally for the whole storybook?

I'm didn't add the fiber optimization as it's been deprecated for some time. It was updated yesterday noting it's incompatible with Node v16.

All in, I think this should be ready to review now. The deploy preview should show the CSS Grid styles in the Auto Columns story as an example. Once approved I can remove the example story.

@tay1orjones tay1orjones marked this pull request as ready for review April 14, 2021 18:11
@tay1orjones tay1orjones requested a review from a team as a code owner April 14, 2021 18:11
@joshblack
Copy link
Contributor Author

bump @andreancardona @emyarod when you get a chance to review! @tay1orjones just pushed up updates and moved this from draft.

Copy link
Contributor

@andreancardona andreancardona left a comment

Choose a reason for hiding this comment

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

yahooo 🎉

@tay1orjones tay1orjones merged commit 48deedf into carbon-design-system:main Apr 15, 2021
@joshblack joshblack deleted the fix/update-storybook-sass branch April 16, 2021 18:17
@tw15egan
Copy link
Member

I pushed a commit to remove fast-sass-loader and use sass-loader in both dev and prod. I tested a fresh storybook dev (yarn start) and see an increase in build time:

fast-sass-loader sass-loader
42s for manager 51s for manager
53s for preview 1min 46s for preview
Recompile time should be less. I also think we'll see a decrease when using sass modules? Also it might help if we imported component-level modules per *-story.js file instead of including all styles globally for the whole storybook?

I'm didn't add the fiber optimization as it's been deprecated for some time. It was updated yesterday noting it's incompatible with Node v16.

All in, I think this should be ready to review now. The deploy preview should show the CSS Grid styles in the Auto Columns story as an example. Once approved I can remove the example story.

Working locally I'm seeing quite a slowdown in both initial startup, as well as any style updates. It's taking me ~50s for style changes to appear in the storybook when running locally. Anything we can do to speed up dev speed?

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