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

After ejecting, unsure of how to add Bourbon / Neat to webpack #837

Closed
lukerollans opened this issue Oct 4, 2016 · 5 comments
Closed

After ejecting, unsure of how to add Bourbon / Neat to webpack #837

lukerollans opened this issue Oct 4, 2016 · 5 comments

Comments

@lukerollans
Copy link

lukerollans commented Oct 4, 2016

I am migrating an existing, server-rendered front-end to a React app. Woo! 🎉

It's my first pure javascript front-end, so I'm a little rusty with things like webpack. I need to bring over Bourbon and Neat which I previously setup in Brunch, so I understand the necessity for include paths etc.

After ejecting, I made the following modifications..

package.json

"devDependencies": {
    ...
    "bourbon": "^4.2.7",
    "bourbon-neat": "^1.8.0",
    ...
}

config/paths.js

// config after eject: we're in ./config/
module.exports = {
  ...
  appSrc: resolveApp('src'),
  bourbon: require("bourbon").includePaths,
  bourbonNeat: require("bourbon-neat").includePaths,
  ...
};

config/webpack.config.dev.js (after also installing node-sass which is working great)

// SASS compatibility!
{
  test: /\.scss/,
  include: [
    paths.bourbon,
    paths.bourbonNeat,
    paths.appSrc
  ],
  loaders: ["style", "css", "sass"]
},

After this, it's my understanding that simply @import "bourbon" from App.scss should work, but I'm getting.

Failed to compile.

Error in ./src/App.scss
Module build failed:
@import "bourbon";
^
      File to import not found or unreadable: bourbon
Parent style sheet: stdin

Does anyone see where I might be going wrong?

@lukerollans
Copy link
Author

After a tiny bit more research I was able to solve it myself. I realised I needed to path the include paths to node-sass, not the loader (which I now understand is a different thing).

Here is what cleared it up for me
https://github.com/jtangelder/sass-loader#sass-options

Hopefully this helps someone else in the future 🎉

@designbyadrian
Copy link

@lukerollans Could you paste your solution, please.

@lukerollans
Copy link
Author

@designbyadrian The above is very slightly out of date if you're using the latest version of create-react-app.

Read this article, plus the comments for a complete guide
https://medium.com/@Connorelsea/using-sass-with-create-react-app-7125d6913760#.ux7zzchnq

@designbyadrian
Copy link

@lukerollans Thank you, but neither article explains how to properly use the value returned from require("bourbon").includePaths as an includePath.

@lukerollans
Copy link
Author

@designbyadrian Yes they do :)

webpack.config.dev.js

  sassLoader: {
    includePaths: [
      paths.bourbon,
      paths.bourbonNeat
    ]
  },

config/paths.js (How I do it, anyway)

// config after eject: we're in ./config/
module.exports = {
  appBuild: resolveApp('build'),
  appPublic: resolveApp('public'),
  appHtml: resolveApp('public/index.html'),
  appIndexJs: resolveApp('src/index.js'),
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
  bourbon: require("bourbon").includePaths,
  bourbonNeat: require("bourbon-neat").includePaths,
  testsSetup: resolveApp('src/setupTests.js'),
  appNodeModules: resolveApp('node_modules'),
  ownNodeModules: resolveApp('node_modules'),
  nodePaths: nodePaths
};

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants