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

Support css-modules #4405

Merged
merged 27 commits into from
Oct 22, 2018
Merged
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7594e87
Support css-modules
chadfawcett Oct 11, 2018
3ccf2bb
Merge branch 'master' of github.com:storybooks/storybook into css-mod…
chadfawcett Oct 11, 2018
535d2b6
Merge branch 'master' of github.com:storybooks/storybook into css-mod…
chadfawcett Oct 13, 2018
0441fc5
Add [module.]scss/sass loader support
chadfawcett Oct 16, 2018
fefd86a
Update yarn.lock
chadfawcett Oct 16, 2018
4a6fd1b
Merge branch 'master' of github.com:storybooks/storybook into css-mod…
chadfawcett Oct 17, 2018
f40b98c
Add specific eslint ignore reasoning and fix default postcss
chadfawcett Oct 17, 2018
b12ffae
Refactor webpack style rules to separate file
chadfawcett Oct 17, 2018
3f88f74
Add sass-loader as core dependency
chadfawcett Oct 17, 2018
da0ad40
Update yarn.lock with bootstrap
chadfawcett Oct 17, 2018
76a668f
Update angular-cli style filter
chadfawcett Oct 17, 2018
39e2c3e
Merge branch 'master' of github.com:storybooks/storybook into css-mod…
chadfawcett Oct 17, 2018
980f394
Revert default webpack config changes
chadfawcett Oct 18, 2018
9719566
Merge branch 'master' of github.com:storybooks/storybook into framewo…
chadfawcett Oct 18, 2018
53004c4
CRA webpack style preset
chadfawcett Oct 18, 2018
41826b6
Add suport for production config
chadfawcett Oct 19, 2018
1753127
Update autoprefixer from revert
chadfawcett Oct 19, 2018
e1b73c7
Check for react-scripts before calling merge
chadfawcett Oct 19, 2018
5949b40
Update yarn.lock
chadfawcett Oct 19, 2018
b2f9e66
Only load react-scripts config newer than v2
chadfawcett Oct 19, 2018
950e2a6
Merge remote-tracking branch 'origin/master' into css-modules
igor-dv Oct 19, 2018
2873911
Move `webpackFinal` so custom webpack config could still edit things :-/
igor-dv Oct 19, 2018
cf34baa
Extract getCraWebpackConfig
chadfawcett Oct 19, 2018
6297d48
Add webpack as dependency to app/react
chadfawcett Oct 19, 2018
5f00d84
Remove module state for imports
chadfawcett Oct 21, 2018
e2cf993
Describe getStyleRules better
chadfawcett Oct 21, 2018
f42fb81
Remove unnecessary concat
chadfawcett Oct 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/core/src/server/config/webpack.config.default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import autoprefixer from 'autoprefixer';
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant to keep this

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@kylemh kylemh Oct 17, 2018

Choose a reason for hiding this comment

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

Very cool - haven't heard of this!

All of the below if for my incoming PR:

So if this is based upon .browserlistrc... What happens when their coverage disagrees with our hard-coded autoprefixer config?

Lastly, I couldn't find anything on supporting PostCSS within CRA 2.0

I'm certain the answer should be: "leave it to them to figure out in full control mode", but should we do anything further for the rare situation where CRA users eject and come up with their own PostCSS config? It should be simple enough, and it further justifies the need to modularize our increasingly complex style-related webpack config logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just trying to stick to what the CRA config had. postcss-preset-env will look at the browserlist set in the package.json, so not sure where this differs from what was there before.

I agree the styles-related webpack config needs to be modularized. To be honest I picked up this PR as I thought it was going to be simple and would allow me to get my toes wet with the codebase. It's turning out to be a bit bigger of a change haha. The more I add the more I'm not sure if I'm conflicting with some of the other apps.

Wouldn't #4411 support PostCSS within CRA 2.0?

Copy link
Member

@kylemh kylemh Oct 17, 2018

Choose a reason for hiding this comment

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

Right! It would, as long as I do a simple conditional tacked onto your .modules check.

I think you should still work without worry. Keep in mind that this .modules paradigm isn't common practice and seems very specific to CRA 2.0

It's conditional logic that precludes CRA 2.0 specifically. You wont infect other consumers at this point.

Copy link
Member

Choose a reason for hiding this comment

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

You're nearly there - apologies for nitpicking - this is good work!

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, nitpicking is fine, I'm just trying to follow along lol.

It looks like the post-css is clashing with the marko package. Both mine and yours are failing that build. I'm not familiar with the marko framework so I'm not 100% sure but it looks like it's because we removed the postcss: {} line from the default config. https://github.com/storybooks/storybook/blob/1f127f0b1d0cdd71708ed4864bc79055b1796f4f/lib/core/src/server/config/webpack.config.default.js#L24

I added that back in and now the marko package seems to work.

Copy link
Member

@kylemh kylemh Oct 17, 2018

Choose a reason for hiding this comment

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

Nice usage of the new suggestion feature 😉

I haven't dived in at all, but I'm certain we can provide an escape hatch for one consumer if we're providing a green path for another.

This could turn into a slippery slope, but we are trying to support one of the biggest consumer bases via this PR.

@ndelangen - know any Marko experts? I haven't checked to see what the issue is, but just figured I'd ask ahead of time.


const cssModuleRegex = /\.module\.css$/;

export function createDefaultWebpackConfig(storybookBaseConfig) {
return {
...storybookBaseConfig,
Expand All @@ -9,6 +11,7 @@ export function createDefaultWebpackConfig(storybookBaseConfig) {
...storybookBaseConfig.module.rules,
{
test: /\.css$/,
exclude: cssModuleRegex,
use: [
require.resolve('style-loader'),
{
Expand All @@ -32,6 +35,20 @@ export function createDefaultWebpackConfig(storybookBaseConfig) {
},
],
},
{
test: cssModuleRegex,
loaders: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
],
Copy link
Member

Choose a reason for hiding this comment

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

we'll still want our default postcss in action here.

You could save line 23-34 as defaultPostcssLoader variable and then spread it into both style loading blobs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! CRA has a getStyleLoaders function and I missed the postcss-loader portion of it.

Copy link
Member

Choose a reason for hiding this comment

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

That is why we need to integrate with cra properly, and not mimicking it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, integrating is the better approach. This is just following how it's currently implemented.

},
{
test: /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2)(\?.*)?$/,
loader: require.resolve('file-loader'),
Expand Down