Issue: a relative beginner to react, who would prefer to use create-react-app without ejecting or configuring webpack, and would like to implement SASS, preferably with a 7-1 folder structure. What I want is isolated stylesheets for the components, but also have global stylesheets for layout, etc. Most importantly, I want to have SASS variables and mixins that I can use in all my components.
What I’ve tried: 1) Node-sass-chokidar (with some scripts added to package.json to automatically run css-watch when you run npm start, as per instructions on github.facebookincubator/create-react-app.)
Node-sass-chokidar finds any scss file in the src directory and compiles it into a corresponding css file in the same directory (same as the scss file, that is).
So, my src directory looks like this:
src
--components
----component-a.jsx
--stylesheets
----abstracts
------variables.scss
------variables.css
----components
------component-a.scss
------component-a.css
… (more 7-1 architecture folders, like base, vendors, etc.)
----main.scss
Problems: Since it creates a .css file next to each .scss file, when i try to import them into my main.scss, i get an error saying “its not clear which file to import. Candidates: component-a.scss, component-a.css. Please delete or rename all but one of these files” Even if i could succesfully import the partials into main.scss, and if i imported the resulting compiled main.css file into index.js or somewhere like that, my components are still reading their styles directly from the compiled css files in stylesheets/components, so they’re not getting the benefit of using variables from stylesheets/abstracts/vars, right?
Btw, package.json looks like this:
{
"name": "s360new",
"version": "0.1.0",
"private": true,
"dependencies": {
"node-sass-chokidar": "0.0.3",
"npm-run-all": "^4.1.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-scripts": "1.0.14"
},
"scripts": {
"build-css": "node-sass-chokidar src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"start": "npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}