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

Add documentation to readme on how to use with sass-loader #42

Closed
ajsharp opened this issue Dec 28, 2015 · 19 comments
Closed

Add documentation to readme on how to use with sass-loader #42

ajsharp opened this issue Dec 28, 2015 · 19 comments

Comments

@ajsharp
Copy link

ajsharp commented Dec 28, 2015

No description provided.

@MoOx
Copy link
Contributor

MoOx commented Dec 28, 2015

Just use sass-loader before (so after in the loader definition). This should not need any specific doc.

@ai
Copy link
Contributor

ai commented Dec 28, 2015

Sorry postcss-loader can’t have a docs for every webpack loader.

I can change my mind if this issue will be popular.

@ai ai closed this as completed Dec 28, 2015
@ajsharp
Copy link
Author

ajsharp commented Dec 28, 2015

@MoOx Yea, I tried that autoprefixer, and it doesn't seem to work. Here's my config:

var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var autoprefixer = require('autoprefixer');
var precss = require('precss');

module.exports = {
  context: __dirname,

  output: {
    path: path.join(__dirname, 'build'),
    filename: '[name].js'
  },

  entry: {
    app: './js/app.js'
  },

  module: {
    loaders: [
      {
        test: /\.(scss|sass)$/,
        loader: ExtractTextPlugin.extract('style-loader', 'css-loader', 'postcss-loader', 'sass-loader')}
    ]
  },

  postcss: function() {
    return [autoprefixer, precss];
  },

  sassLoader: {
    includePaths: [path.join(__dirname, 'scss')]
  },

  plugins: [
    new ExtractTextPlugin('styles.css')
  ]
}

Here's the sass file:

.banner {
  background-color: green;
  font-size: 48px;
  text-align: center;
  color: white;
  border-radius: 4px;
  box-shadow: black 1px 1px 1px;
  transform: rotate(7deg);
}

And the output file:

.banner {
  background-color: green;
  font-size: 48px;
  text-align: center;
  color: white;
  border-radius: 4px;
  box-shadow: black 1px 1px 1px;
  transform: rotate(7deg);
}

@ai Using this loader with sass or less is an extremely common use-case -- no one in practice is writing plain-vanilla CSS. I think it would be very useful to have a concrete example of how to use these tools together.

@ai
Copy link
Contributor

ai commented Dec 28, 2015

I am open for PR. But try to suggest some compact changes. We already have too many config for different cases.

@MoOx
Copy link
Contributor

MoOx commented Dec 28, 2015

@ajsharp I think you are not using ExtractTextPlugin the right way.
You should use loader: ExtractTextPlugin.extract('style-loader', ['css-loader', 'postcss-loader', 'sass-loader'])} (an array for the default loaders you want to use, the first parameter is used when extracttextplugin is disabled (so optional).

@ajsharp
Copy link
Author

ajsharp commented Dec 29, 2015

@MoOx Ah, that was it 😄 Thanks very much for the help.

@mattdanna
Copy link

+1

@chrisbarless
Copy link

@MoOx this saved my life

@occultskyrong
Copy link

In the .scss file, use the Chinese comments,
will complain ‘Unknown word’,
I have used in scss the @charset 'utf-8'

@l-zhi
Copy link

l-zhi commented May 11, 2016

@MoOx Ah +1

@dqisme
Copy link

dqisme commented May 13, 2016

@MoOx gooood job!

@rmoddel
Copy link

rmoddel commented May 25, 2016

@MoOx Thanks!!

@aseem2625
Copy link

Using auto prefixer as last 2 versions of browser doesn't add prefixes but if I remove 'last 2 versions' then it works fine. Can someone tell me how does this happen?

postcss: function () {
    return [autoprefixer({browsers: ['last 2 versions']})];
},

@MoOx
Also, can you please tell me what do you mean by "an array for the default loaders you want to use, the first parameter is used when extracttextplugin is disabled (so optional)."

I mean, by your 'first parameter is optional' will my style-loader be ignored?
loader: ExtractTextPlugin.extract('style-loader', ['css-loader', 'postcss-loader', 'sass-loader'])

@sertaconay
Copy link

@aseem2625 It's because last 2 versions of browsers don't need any prefix. :p

@kutsan
Copy link

kutsan commented Mar 31, 2017

Not related but this is somehow top Google result. Here is my Stylus, PostCSS, Webpack 2 config for React, if someone needs.

@YousefMMS
Copy link

I just used it like so loader: 'style-loader!css-loader!postcss-loader!sass-loader' and it works with me, is this may generate any other issue?

@IamManchanda
Copy link

IamManchanda commented Oct 25, 2017

@ai I think It should reopen with webpack being so popular!

@ai
Copy link
Contributor

ai commented Oct 25, 2017

@IamManchanda I am not a maintainer anymore =^_^= ask @michael-ciniawsky

@himdel
Copy link

himdel commented Oct 26, 2018

I think there may be differing definitions of what "works for me" means here.

loader: 'style-loader!css-loader!postcss-loader!sass-loader'

indeed works fine .. until you need to do @import "~package/file" in your sass and find out that postcss is completely ignoring webpack resolvers and fails on path not found.

Still no idea how to order the plugins so that this works. (And yes, it works fine if postcss-loader is removed from the mix.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests