-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Use postcss.config.js when present #4411
Changes from 5 commits
b205946
4dd6269
92538a7
5ea6161
9ab0c20
8703d83
3337585
9250f1e
6f22d66
d413841
d785ab3
7bac401
dfa78c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import autoprefixer from 'autoprefixer'; | ||
import findUp from 'find-up'; | ||
|
||
export function createDefaultWebpackConfig(storybookBaseConfig) { | ||
const postcssConfig = findUp.sync('postcss.config.js', { | ||
cwd: storybookBaseConfig.context, | ||
}); | ||
|
||
return { | ||
...storybookBaseConfig, | ||
module: { | ||
|
@@ -19,16 +24,18 @@ export function createDefaultWebpackConfig(storybookBaseConfig) { | |
}, | ||
{ | ||
loader: require.resolve('postcss-loader'), | ||
options: { | ||
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options | ||
postcss: {}, | ||
plugins: () => [ | ||
require('postcss-flexbugs-fixes'), // eslint-disable-line | ||
autoprefixer({ | ||
flexbox: 'no-2009', | ||
}), | ||
], | ||
}, | ||
options: postcssConfig | ||
? { | ||
postcssConfig, | ||
} | ||
: { | ||
plugins: () => [ | ||
require('postcss-flexbugs-fixes'), // eslint-disable-line global-require | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that something won't work if this plugin will be missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plugins are currently available, correct? I didn't remove dependencies for that reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, should we somehow merge it to the user's config? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I wouldn't do that. Either we give them a set of defaults, or they have full control. I'm not a fan of doing obscure things like providing a pair of plugins the user may or may not want if they have their own postcss config. |
||
autoprefixer({ | ||
flexbox: 'no-2009', | ||
}), | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
|
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.
should it be
{ ...postcssConfig }
?I think will be better something like this:
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 the config would work without a spread operator, but adding it doesn't hurt anything, so I will 👍
I'm totally fine with that! I do my best to not subscribe to lint beliefs and simply adhere to the linting of the code base. I have seen @ndelangen express a favor towards ternaries when discussing short-circuits, so I did it that way; perhaps a lint rule is in order to prevent further confusion?
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 was more about to simplify the readability. Maybe even worth to extract it to a func
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.
is subjective.
I think ternaries read fine,
but most importantly this discussion shouldn't even happen. We should just have a lint rule to prevent bike-shedding. I want to do whatever the team wants to do here.Doesn't look like ESLint has a rule to prevent this discussion aside from preventing ternaries at all. It'd be cool to see a
prefer-short-circuit
lint rule which favors&&
or||
instead of ternaries where one option isnull
orundefined
Anywho... I'll go ahead and make both of those changes.