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

added rcs- prefix for all CSS classes using CSS-Modules #51

Merged
merged 4 commits into from
Aug 17, 2018
Merged

added rcs- prefix for all CSS classes using CSS-Modules #51

merged 4 commits into from
Aug 17, 2018

Conversation

sag1v
Copy link
Contributor

@sag1v sag1v commented Aug 14, 2018

should cover #43
I know there's another PR for adding a prefix for the css classes #45 but i think this solution using css-modules can perform better at scale.

Note that i updated the readme with the new rcs- prefix and i think we should bump a major version as this is a breaking change.

@@ -1,8 +1,8 @@
import React from 'react'
import TestUtils from 'react-dom/test-utils'
import reactDOM from 'react-dom'
import CustomScroll from 'customScroll.js'
import '../main/cs.scss'
import CustomScroll from '../main/customScroll.js'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why CustomScroll was imported from production instead of the dev environment.

Copy link
Owner

@rommguy rommguy left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!
I can't see changes in the cs.scss file. Did you change the target css directly ?
Can you please explain the solution in general. I understand why I should add "rcs" prefix to all classes but what else does this change include ?
thanks

@@ -24,7 +24,7 @@ module.exports = [{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
use: ['css-loader?sourceMap&modules&camelCase=dashes&localIdentName=rcs-[local]', 'sass-loader']
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this change needed ? I know that if you want source maps for css you need to add options object with sourceMap: true, to both sass-loader and css-loader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rommguy I didn't change the css file directly, i configured webpack to do it via css-modules.
This is why i refactor the usage of the css clasees.
So this

import './path/to/file.css
// ...
className="some-class"

Refactored to this:

import styles from './path/to/file.css
// ...
className={styles.someClass}

each class within the css file will be prefixed with the localIdentName (rcs in our case).

As for the sourceMap this was not intentional, I'm used to add this by default but it shouldn't be part of this PR. 😄

Copy link
Owner

@rommguy rommguy Aug 17, 2018

Choose a reason for hiding this comment

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

Very cool, just read about the localIdentName, I wasn't familiar with that option, I thought it's always a generated hash.
Why did you decide to use the url format configuration instead of the options object ?
I saw the usage of options object here - css-loader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very cool, just read about the localIdentName, I wasn't familiar with that option

Yeah! i usually add the folder as well so i get the component name (depends on the files structure) as part of the css class.

class="MyComponent-my-class"

You can read about it here

Why did you decide to use the url format configuration instead of the options object ?

Actually no special reason, i usually use the options object, but i wasn't sure what format you like and it is inside the ExtractTextPlugin.extract object so i thought separating each loader to on object instead of string can look less readable.
If you think we need to go with options fine by me!

Copy link
Owner

@rommguy rommguy Aug 17, 2018

Choose a reason for hiding this comment

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

ok, lets go for the options object, I prefer it over the url format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rommguy done.

@rommguy rommguy merged commit 236e570 into rommguy:gh-pages Aug 17, 2018
@rommguy
Copy link
Owner

rommguy commented Aug 17, 2018

I merged, will publish a new version to npm.
Any idea why the package-lock.json has so many changes ?

@sag1v
Copy link
Contributor Author

sag1v commented Aug 18, 2018

I dont know actually.
It got re-generated after i did npm install.

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.

2 participants