Skip to content

Used React-App-Rewired to allow scss modules and svg imports on a vanilla create-react-app installation.

Notifications You must be signed in to change notification settings

akrigline/create-react-app-scss-rewired

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project was bootstrapped with Create React App.

In addition to the vanilla setup from create-react-app I've used React App Rewired to tweak 2 things:

  • SCSS is now enabled in conjunction with CSS Modules.
  • SASS Resources Loader is configured targetting the /style/resources directory. This is really just a QOL thing and can be removed pretty easily.
  • SVG React Loader is enabled to allow treating svgs as components.

How to use SCSS in this configuration

This particular setup is only for those seeking to use SCSS CSS Modules, it breaks pretty magnificently otherwise.

// components/app/app.scss
.someClass {
  foo: bar;
  div {
    bit: baz;
  }
}
// components/app/app.js
import styles from './app.scss'

// ...

render () {
  return {
    <div className={styles.someClass}>
      <div>Some Div Content styled by the nested rule.</div>
    </div>
  }
}

How to use SVGs in this configuration

I have set up SVG React Loader to wrap all imported SVGs as components. Once imported, you can simply use them as you would a component. These svgs are then inlined in the HTML, so you can use SCSS to style and manipulate them as necessary.

// components/app/app.js
import SomeIcon from '../../assets/icons/someIcon.svg'

// ...
render () {
  return {
    <div>
      <SomeIcon />
    </div>
  }
}

Giving them a className is just the same as if they were divs

// components/app/app.scss
.svgClass {
  foo: bar;
}
// components/app/app.js
import styles from './app.scss'
import SomeIcon from '../../assets/icons/someIcon.svg'

// ...

render () {
  return {
    <div>
      <SomeIcon className={styles.svgClass} />
    </div>
  }
}

About

Used React-App-Rewired to allow scss modules and svg imports on a vanilla create-react-app installation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published