7

I'm rewriting an "old" React prototype that uses Bourbon, it also uses gulp-sass in a gulpfile to inject a node-neat dependency:

var sassOptions = {
    includePaths: require('node-neat').includePaths,
};

I'd like to use the create-react-app boilerplate and have a "simple" workflow for the styles by using an npm script to compile the sass files (also because create-react-app restricts you on that) but I can't figure out how to do that.

"build-css": "node-sass src/styles/ -o src/",
"watch-css": "npm run build-css && node-sass src/styles/ -o src/ --watch --recursive"

I'll probably rewrite the styles in the future using a different approach (maybe use styled components, maybe keep using Sass and dismiss Bourbon entirely) but I just need to port the Sass styles from the old project for now.

Any ideas on integrating create-react-app (without ejecting) and Bourbon/Neat?

Is there a way to get the neat.includePaths bit into the node-sass one-liner script in package.json, for example?

RobC
  • 22,977
  • 20
  • 73
  • 80
zok
  • 6,065
  • 10
  • 43
  • 65
  • Minor side note but you should probably swap out `node-neat` for `bourbon-neat`. `node-neat`is a port and tends to be behind the official release. https://www.npmjs.com/package/bourbon-neat – whmii Apr 20 '17 at 14:27
  • thanks a lot man. any help is greatly appreciated. – zok Apr 20 '17 at 14:39
  • 1
    Your best bet is to check outNeat NPM documentation at https://github.com/thoughtbot/neat#installing-with-npm-and-using-a-node-based-asset-pipeline As an alternative you may want to try http://eyeglass.rocks/ as a way of handling your sass and dependencies. Sadly react is pretty outside of my wheelhouse so that's the best advice I can give. – whmii Apr 21 '17 at 19:49
  • 1
    hey did you ever end up finding a solution to this? – AgileNinja Oct 30 '17 at 21:27

1 Answers1

0

As far as I know, you can not evaluate the includePaths you need to be able import Bourbon and Neat through the one-liner in package.json.

However, you can still use Bourbon +Neat with your non-ejected React app. If you keep your package.json changes as described by React here, install the gems on your machine and install them locally in your Sass directories where you see fit. As an example;

  • /src
    • /styles
      • /vendors
        • /bourbon
        • /neat
        • /other-sass-library
      • /base
      • /layout
      • /...
    • App.js
    • ...

When having the gems installed, you run the commands where you want them installed. bourbon install --path <some-path> and neat install.

When you can reference Bourbon and Neat this way, it's no problem to simply @import vendors/bourbon/bourbon etc.

Of course, this way of managing styles are not on par with the co-located, module thinking of React/Webpack, but sometimes there's definitely a need for a fully controlled Sass styles tree.

miphe
  • 1,763
  • 1
  • 20
  • 33