Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Question: How do I use sass-loader? #755

Closed
eluchsinger opened this issue Mar 21, 2018 · 7 comments
Closed

Question: How do I use sass-loader? #755

eluchsinger opened this issue Mar 21, 2018 · 7 comments

Comments

@eluchsinger
Copy link

I am trying out neutrino and I have the requirement to use SASS (or SCSS). I can't get it to work. Only the App.css gets compiled and the styles.sass is ignored. I have also tried to add an include path in the sass-loader options. I don't get any error messages.

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "build": "neutrino build",
    "start": "neutrino start",
    "lint": "neutrino lint",
    "test": "neutrino test"
  },
  "dependencies": {
    "@neutrinojs/style-loader": "^8.1.2",
    "node-sass": "^4.7.2",
    "prop-types": "^15.6.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-hot-loader": "^4.0.0"
  },
  "devDependencies": {
    "@neutrinojs/airbnb": "^8.1.2",
    "@neutrinojs/jest": "^8.1.2",
    "@neutrinojs/react": "^8.1.2",
    "neutrino": "^8.1.2",
    "neutrino-middleware-sass": "^0.0.1",
    "node-sass-chokidar": "^1.2.0",
    "sass-loader": "^6.0.7"
  }
}

grafik

@eliperelman
Copy link
Member

The react preset already comes with style-loader, so maybe it's possible there is a conflict going on here somewhere. Could you change your .neutrinorc.js to the following and try it?

module.exports = {
  use: [
    '@neutrinojs/airbnb',
    ['@neutrinojs/react', {
      html: {
        title: 'test'
      },
      style: {
        loaders: [
          { loader: 'sass-loader', useId: 'sass' }
        ]
      }
    }]
  ]
};

If that doesn't work, also try using require.resolve:

{ loader: require.resolve('sass-loader'), useId: 'sass' }

Let us know!

@eluchsinger
Copy link
Author

eluchsinger commented Mar 21, 2018

I tried both, but the styles.sass file didn't get compiled.

module.exports = {
  use: [
    '@neutrinojs/airbnb',
    ['@neutrinojs/react', {
      html: {
        title: 'test'
      },
      style: {
        loaders: [
          { loader: require.resolve('sass-loader'), useId: 'sass' }
        ]
      }
    }]
  ]
};

@eliperelman
Copy link
Member

@timkelty Am I missing something here?

@timkelty
Copy link
Contributor

timkelty commented Mar 21, 2018

@eliperelman @eluchsinger You need to tell style-loader to process .sass files with the test/modulesTest options (by default it only handles .css files)

module.exports = {
  use: [
    '@neutrinojs/airbnb',
    ['@neutrinojs/react', {
      html: {
        title: 'test'
      },
      style: {
        test: /\.sass$/,
        modulesTest: /\.module\.sass$/,
        loaders: [
          { loader: require.resolve('sass-loader'), useId: 'sass' }
        ]
      }
    }]
  ]
};

@edmorley
Copy link
Member

@eluchsinger did the approach above work for you?

If so, it would be great to add a Saas example to the docs, since this came up in #803 too.

@eluchsinger
Copy link
Author

eluchsinger commented Apr 25, 2018

@edmorley I think it worked, but in the end I didn't use this tool at all (therefore, I can't re-check again).

@eliperelman
Copy link
Member

Also came up in #871.

edmorley added a commit that referenced this issue May 18, 2018
Since unless the default file extension regex is overridden, the
`.sass` (old style) or `.scss` (new style) Sass styles will not
be seen by `sass-loader`:
https://github.com/webpack-contrib/sass-loader#examples
https://sass-lang.com/documentation/file.SASS_REFERENCE.html

Closes #755.
Closes #803.
Refs #871.
edmorley added a commit that referenced this issue Oct 12, 2018
To try and prevent the confusion caused when users do things like:
* using `@neutrinojs/react` followed by `@neutrinojs/web`, which
  clobbers the React parts of the config:
  #1129 (comment)
* using `@neutrinojs/react` followed by `@neutrinojs/style`, which
  causes incorrect `extract` and `hot` configuration:
  #1129 (comment)
  #755 (comment)
  #803 (comment)
  #869 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants