-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
SASS precision & CSS Modules configuration #1934
SASS precision & CSS Modules configuration #1934
Conversation
Deploy preview ready! Built with commit d729eb6 |
Deploy preview failed. Built with commit d85f726 https://app.netlify.com/sites/using-glamor/deploys/59a4a8eacf321c44fec01164 |
This looks great! Some nice refactoring & new functionality/tests ❤️ |
But hmmm some of the tests are failing atm because the |
Hmmm they passed locally (works on my machine!) but maybe that's because I had |
|
||
export function getLocalIdentName() { | ||
return isProduction() | ||
? `[hash:base64]` // Webpack default if unspecified |
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.
see webpack-contrib/css-loader#406 its actually more efficient to use the name with the path and name and local with a sort hash
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.
Good to know! Would you recommend sticking with [path]---[name]---[local]---[hash:base64:5]
for both dev and prod then?
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.
yup!
@@ -1,8 +1,11 @@ | |||
import ExtractTextPlugin from "extract-text-webpack-plugin" | |||
import cssModulesConfig from "gatsby/dist/utils/css-modules-config" |
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.
this is not a great pattern i don't think :/ it makes it really hard to understand what bits of the gatsby package are public and which aren't. Not to mention it ties the plugin to specific versions of gatsby that isn't documented anywhere
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.
Hmm yeah. We don't have good patterns yet for exposing public helper functions 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.
OK. Would adding gatsby
as a devDependency of these plugins be a bad idea? I guess so. Any suggestions for how to share the CSS Modules configuration between the core webpack.config.js
and the different plugins? I thought about using an environment variable but didn't think that would be a good idea.
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.
Elaborating on this idea—I initially thought that storing the localIdentName
config in an environment variable would not only make it reusable between plugins but also easily configurable by the user. However, the documented method of setting environment variables via .env.*
files would not work because this environment variable would have to be available at the time webpack.config.js
is evaluated, i.e. before DefinePlugin
is loaded.
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 v2 handles this neatly for the webpack case, we pass in essentially this helper to the plugin, vs the plugin requesting it.
Generally I think it makes the most sense to do either:
- pass what is needed to gatsby plugins via the plugin api
- extract the helper into a separately versioned package (MONOREEEEEEEPOOOOOO)
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.
MONOREEEEEEEPOOOOOO
LOL! And yeah, that seems like the nicest solution for now — super easy to make a new package (npm run plop
). Add gatsby-1
to the package name so it's super obvious this is only needed for Gatsby 1 as it sounds like we can do things differently in v2.
Thanks! Making new release. |
Hiya @mingaldrichgan! 👋 This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here. Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! 💪💜 |
This pull request replaces #1900 — please refer to my correspondence with @KyleAMathews there for more context.
1. SASS precision option
SASS defaults to 5 digits of precision, which is too low for Bootstrap. This pull request adds a
precision
option togatsby-plugin-sass
andgatsby-plugin-postcss-sass
.2. CSS Modules configuration
In my original pull request, I made the CSS Modules
localIdentName
configurable forgatsby-plugin-sass
. My use case for that was to include the[path]
(for development, as it is not uncommon to have CSS files with the same name in different folders). Kyle suggested that we include[path]
by default, in which case I don't think there is much value in making this configurable.In this pull request, I refactored out the CSS Modules configuration from
webpack.config.js
and the various plugins intogatsby/src/utils/css-modules-config.js
. Although thelocalIdentName
is not currently configurable, thegetLocalIdentName()
function now acts as a single source of truth and can be easily changed/extended in the future.3. gatsby-plugin-react-css-modules
This is a new package for integrating
babel-plugin-react-css-modules
into a Gatsby project. This is certainly not required to use CSS Modules, but it is an option.4. Miscellaneous
While working on this, I noticed that
gatsby-plugin-sass
did not configure the SASS loader for thedevelop-html
stage, whereasgatsby-plugin-postcss-sass
did. This is also included in this pull request.