Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure webpack to use compass in my project

I'm new in webpack and i don't know how we can use Compass ( CSS Authoring Framework ) in a project.

Is there a good method ?

Thanks

like image 547
David Auvray Avatar asked Oct 03 '15 17:10

David Auvray


2 Answers

you can use compass-mixins

var path = require('path');
module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.scss$/,
        loader: "style!css!sass?includePaths[]=" + path.resolve(__dirname, "./node_modules/compass-mixins/lib")
      }
    ]
  }
};

here is a helpful webpack boilerplate


Update:

You can use sass-resources-loader that will @import your SASS resources into every required SASS module. where you will never have to import your resources in all your sass files.

module.exports = {
  ...,
  module: {
    loaders: [
      ...,
      {
        test: /\.scss$/,
        loaders: [
          'style',
          'css',
          'sass?outputStyle=expanded&includePaths[]=' + path.resolve(__dirname, './node_modules/compass-mixins/lib'),
          'sass-resources'
        ]
      }
    ]
  },
  sassResources: path.resolve(__dirname, './client/app/resources/stylesheets/base.scss')

please check the implementation in action in this boilerplate

like image 67
Evan Lévesque Avatar answered Sep 24 '22 10:09

Evan Lévesque


Essential addition to @Ayman Jitan answer https://stackoverflow.com/a/34967698/1114926.

You have to add these two lines at top of your styles.scss file:

@import "compass";  // <--
@import "compass/functions";  // <--

.foo {
    min-height: 100px;
    background-color: #fff;
}

Otherwise you'll get errors from sass-loader "Module build failed" and "No mixin" found. Like the following"

Module build failed:
undefined
                ^
      No mixin named background

If you add only @import "compass/functions"; (without @import "compass";), you may get this error (depends on the mixin you include, in my case it was thrown by @include background(linear-gradient(white, #cccccc, #aaaaaa));):

Module build failed:
undefined
                          ^
      Media query expression must begin with '('
like image 30
Green Avatar answered Sep 23 '22 10:09

Green