Git Product home page Git Product logo

sass-loader's Introduction

npm node tests coverage discussion size

sass-loader

Loads a Sass/SCSS file and compiles it to CSS.

Getting Started

To begin, you'll need to install sass-loader:

npm install sass-loader sass webpack --save-dev

or

yarn add -D sass-loader sass webpack

or

pnpm add -D sass-loader sass webpack

sass-loader requires you to install either Dart Sass, Node Sass on your own (more documentation can be found below) or Sass Embedded.

This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.

Note

We highly recommend using Dart Sass.

Warning

Node Sass does not work with Yarn PnP feature and doesn't support @use rule.

Warning

Sass Embedded is experimental and in beta, therefore some features may not work

Chain the sass-loader with the css-loader and the style-loader to immediately apply all styles to the DOM or the mini-css-extract-plugin to extract it into a separate file.

Then add the loader to your Webpack configuration. For example:

app.js

import "./style.scss";

style.scss

$body-color: red;

body {
  color: $body-color;
}

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          // Creates `style` nodes from JS strings
          "style-loader",
          // Translates CSS into CommonJS
          "css-loader",
          // Compiles Sass to CSS
          "sass-loader",
        ],
      },
    ],
  },
};

Finally run webpack via your preferred method.

The outputStyle (old API) and style (new API) options in production mode

For production mode, the outputStyle (old API) and style (new API) options default to compressed unless otherwise specified in sassOptions.

Resolving import at-rules

Webpack provides an advanced mechanism to resolve files.

The sass-loader uses Sass's custom importer feature to pass all queries to the Webpack resolving engine. Thus you can import your Sass modules from node_modules.

@import "bootstrap";

Using ~ is deprecated and can be removed from your code (we recommend it), but we still support it for historical reasons. Why can you remove it? The loader will first try to resolve @import as a relative path. If it cannot be resolved, then the loader will try to resolve @import inside node_modules.

Prepending module paths with a ~ tells webpack to search through node_modules.

@import "~bootstrap";

It's important to prepend it with only ~, because ~/ resolves to the home directory. Webpack needs to distinguish between bootstrap and ~bootstrap because CSS and Sass files have no special syntax for importing relative files. Writing @import "style.scss" is the same as @import "./style.scss";

Problems with url(...)

Since Sass implementations don't provide url rewriting, all linked assets must be relative to the output.

  • If you pass the generated CSS on to the css-loader, all urls must be relative to the entry-file (e.g. main.scss).
  • If you're just generating CSS without passing it to the css-loader, it must be relative to your web root.

You will be disrupted by this first issue. It is natural to expect relative references to be resolved against the .sass/.scss file in which they are specified (like in regular .css files).

Thankfully there are a two solutions to this problem:

  • Add the missing url rewriting using the resolve-url-loader. Place it before sass-loader in the loader chain.
  • Library authors usually provide a variable to modify the asset path. bootstrap-sass for example has an $icon-font-path.

Options

implementation

Type:

type implementation = object | string;

Default: sass

The special implementation option determines which implementation of Sass to use.

By default the loader resolve the implementation based on your dependencies. Just add required implementation to package.json (sass or node-sass package) and install dependencies.

Example where the sass-loader loader uses the sass (dart-sass) implementation:

package.json

{
  "devDependencies": {
    "sass-loader": "^7.2.0",
    "sass": "^1.22.10"
  }
}

Example where the sass-loader loader uses the node-sass implementation:

package.json

{
  "devDependencies": {
    "sass-loader": "^7.2.0",
    "node-sass": "^5.0.0"
  }
}

Beware the situation when node-sass and sass were installed! By default the sass-loader prefers sass. In order to avoid this situation you can use the implementation option.

The implementation options either accepts sass (Dart Sass) or node-sass as a module.

object

For example, to use Dart Sass, you'd pass:

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              // Prefer `dart-sass`
              implementation: require("sass"),
            },
          },
        ],
      },
    ],
  },
};

string

For example, to use Dart Sass, you'd pass:

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              // Prefer `dart-sass`
              implementation: require.resolve("sass"),
            },
          },
        ],
      },
    ],
  },
};

sassOptions

Type:

type sassOptions =
  | import("sass").LegacyOptions<"async">
  | ((
      content: string | Buffer,
      loaderContext: LoaderContext,
      meta: any,
    ) => import("sass").LegacyOptions<"async">);

Default: defaults values for Sass implementation

Options for Dart Sass or Node Sass implementation.

Note

The charset option has true value by default for dart-sass, we strongly discourage change value to false, because webpack doesn't support files other than utf-8.

Note

The indentedSyntax option has true value for the sass extension.

Note

Options such as data and file are unavailable and will be ignored.

ℹ We strongly discourage change outFile, sourceMapContents, sourceMapEmbed, sourceMapRoot options because sass-loader automatically sets these options when the sourceMap option is true.

Note

Access to the loader context inside the custom importer can be done using the this.webpackLoaderContext property.

There is a slight difference between the sass (dart-sass) and node-sass options.

Please consult documentation before using them:

object

Use an object for the Sass implementation setup.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              sassOptions: {
                indentWidth: 4,
                includePaths: ["absolute/path/a", "absolute/path/b"],
              },
            },
          },
        ],
      },
    ],
  },
};

function

Allows to setup the Sass implementation by setting different options based on the loader context.

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              sassOptions: (content, loaderContext) => {
                // More information about available properties https://webpack.js.org/api/loaders/
                const { resourcePath, rootContext } = loaderContext;
                const relativePath = path.relative(rootContext, resourcePath);

                if (relativePath === "styles/foo.scss") {
                  return {
                    includePaths: ["absolute/path/c", "absolute/path/d"],
                  };
                }

                return {
                  includePaths: ["absolute/path/a", "absolute/path/b"],
                };
              },
            },
          },
        ],
      },
    ],
  },
};

sourceMap

Type:

type sourceMap = boolean;

Default: depends on the compiler.devtool value

Enables/Disables generation of source maps.

By default generation of source maps depends on the devtool option. All values enable source map generation except eval and false value.

ℹ If a true the sourceMap, sourceMapRoot, sourceMapEmbed, sourceMapContents and omitSourceMapUrl from sassOptions will be ignored.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              sourceMap: true,
            },
          },
          {
            loader: "sass-loader",
            options: {
              sourceMap: true,
            },
          },
        ],
      },
    ],
  },
};

ℹ In some rare cases node-sass can output invalid source maps (it is a node-sass bug).

In order to avoid this, you can try to update node-sass to latest version or you can try to set within sassOptions the outputStyle option to compressed.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              sourceMap: true,
              sassOptions: {
                outputStyle: "compressed",
              },
            },
          },
        ],
      },
    ],
  },
};

additionalData

Type:

type additionalData =
  | string
  | ((content: string | Buffer, loaderContext: LoaderContext) => string);

Default: undefined

Prepends Sass/SCSS code before the actual entry file. In this case, the sass-loader will not override the data option but just prepend the entry's content.

This is especially useful when some of your Sass variables depend on the environment:

string

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              additionalData: "$env: " + process.env.NODE_ENV + ";",
            },
          },
        ],
      },
    ],
  },
};

function

Sync
module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              additionalData: (content, loaderContext) => {
                // More information about available properties https://webpack.js.org/api/loaders/
                const { resourcePath, rootContext } = loaderContext;
                const relativePath = path.relative(rootContext, resourcePath);

                if (relativePath === "styles/foo.scss") {
                  return "$value: 100px;" + content;
                }

                return "$value: 200px;" + content;
              },
            },
          },
        ],
      },
    ],
  },
};
Async
module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              additionalData: async (content, loaderContext) => {
                // More information about available properties https://webpack.js.org/api/loaders/
                const { resourcePath, rootContext } = loaderContext;
                const relativePath = path.relative(rootContext, resourcePath);

                if (relativePath === "styles/foo.scss") {
                  return "$value: 100px;" + content;
                }

                return "$value: 200px;" + content;
              },
            },
          },
        ],
      },
    ],
  },
};

webpackImporter

Type:

type webpackImporter = boolean;

Default: true

Enables/Disables the default Webpack importer.

This can improve performance in some cases. Use it with caution because aliases and @import at-rules starting with ~ will not work. You can pass own importer to solve this (see importer docs).

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              webpackImporter: false,
            },
          },
        ],
      },
    ],
  },
};

warnRuleAsWarning

Type:

type warnRuleAsWarning = boolean;

Default: true

Treats the @warn rule as a webpack warning.

style.scss

$known-prefixes: webkit, moz, ms, o;

@mixin prefix($property, $value, $prefixes) {
  @each $prefix in $prefixes {
    @if not index($known-prefixes, $prefix) {
      @warn "Unknown prefix #{$prefix}.";
    }

    -#{$prefix}-#{$property}: $value;
  }
  #{$property}: $value;
}

.tilt {
  // Oops, we typo'd "webkit" as "wekbit"!
  @include prefix(transform, rotate(15deg), wekbit ms);
}

The presented code will throw webpack warning instead logging.

To ignore unnecessary warnings you can use the ignoreWarnings option.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              warnRuleAsWarning: true,
            },
          },
        ],
      },
    ],
  },
};

api

Type:

type api = "legacy" | "modern" | "modern-compiler";

Default: "legacy"

Allows you to switch between legacy and modern API. You can find more information here. The modern-compiler option enables the modern API with support for Shared Resources.

Note

Using modern-compiler and sass-embedded together significantly improve performance and decrease built time. We strongly recommend their use. We will enable them by default in a future major release.

Warning

The sass options are different for modern and old APIs. Please look at docs how to migrate on new options.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "sass-loader",
            options: {
              api: "modern",
              sassOptions: {
                // Your sass options
              },
            },
          },
        ],
      },
    ],
  },
};

How to enable @debug output

Defaults, the output of @debug messages is disabled. To enable it, add to webpack.config.js following:

module.exports = {
  stats: {
    loggingDebug: ["sass-loader"],
  },
  // ...
};

Examples

Extracts CSS into separate files

For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.

There are four possibilities to extract a style sheet from the bundle:

webpack.config.js

const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          // fallback to style-loader in development
          process.env.NODE_ENV !== "production"
            ? "style-loader"
            : MiniCssExtractPlugin.loader,
          "css-loader",
          "sass-loader",
        ],
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: "[name].css",
      chunkFilename: "[id].css",
    }),
  ],
};

webpack.config.js

module.exports = {
  entry: [__dirname + "/src/scss/app.scss"],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [],
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        type: "asset/resource",
        generator: {
          filename: "bundle.css",
        },
        use: ["sass-loader"],
      },
    ],
  },
};

3. extract-loader (simpler, but specialized on the css-loader's output)

4. file-loader (deprecated--should only be used in Webpack v4)

webpack.config.js

module.exports = {
  entry: [__dirname + "/src/scss/app.scss"],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [],
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "file-loader",
            options: { outputPath: "css/", name: "[name].min.css" },
          },
          "sass-loader",
        ],
      },
    ],
  },
};

(source: https://stackoverflow.com/a/60029923/2969615)

Source maps

Enables/Disables generation of source maps.

To enable CSS source maps, you'll need to pass the sourceMap option to the sass-loader and the css-loader.

webpack.config.js

module.exports = {
  devtool: "source-map", // any "source-map"-like devtool is possible
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              sourceMap: true,
            },
          },
          {
            loader: "sass-loader",
            options: {
              sourceMap: true,
            },
          },
        ],
      },
    ],
  },
};

If you want to edit the original Sass files inside Chrome, there's a good blog post. Checkout test/sourceMap for a running example.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

sass-loader's People

Contributors

akiran avatar alexander-akait avatar anshumanv avatar cap-bernardito avatar chicoxyzzy avatar dependabot[bot] avatar dirtyhenry avatar ersachin3112 avatar evilebottnawi avatar g-plane avatar hinok avatar jamesgeorge007 avatar jhnns avatar jorrit avatar joshwiens avatar jstcki avatar jtangelder avatar justin808 avatar michael-ciniawsky avatar nex3 avatar nhevia avatar notzheng avatar oopschen avatar philwareham avatar pmowrer avatar rahavlussato avatar renspoesse avatar roman-vanesyan avatar simon04 avatar snitin315 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sass-loader's Issues

Can't get hot module replacement to work with sass-loader version newer than 0.2.0

I'm trying to update my rails-webpack-reactjs tutorial project to the latest dependencies.

https://github.com/justin808/react-webpack-rails-tutorial/tree/update-to-latest

The only dependency that does not work is sass-loader. Any version greater than 0.2.0 gives the following error:

ERROR in ../~/css-loader!../~/sass-loader?outputStyle=expanded&imagePath=/assets/images&includePaths[]=/Users/justin/j/react/react-webpack-rails-tutorial/webpack/assets/stylesheets!./assets/stylesheets/test-sass-stylesheet.scss
TypeError: Object function (from) {
            return !!~this.indexOf(from);
        } has no method 'replace'

Thus, I'm stuck at 0.2.0. Any ideas on what I can do further pinpoint what change broke my app?

Has anybody else gotten the hot-reload server to work with a version greater than 0.2.0?

Thanks.

Pass variables to scss files

I'm wanting to pass variables from webpack to the scss files, for example opacity is able to be changed by a user and stored in the db. Ideally I'd pass the variable same way as you do to JS files via webpack and pass them straight through to the SCSS files before compilation.

Hot Module Replacement breaks on 0.3.1

HMR works on the exact same codebase on 0.2.0 and not on 0.3.1.

Steps to Reproduce

  1. Start the Webpack Dev Server
  2. Change a .scss file

Expected Result

Webpack recompiles the file and resends it to the browser.

Actual Result

It works on 0.2.0. Nothing happens on 0.3.1. (Webpack doesn't even recompile the file.)

Notes

In 0.3.1, I get this error on every compile:

File to import not found or unreadable: Roboto

I do not get it in 0.2.0.

Here's the only import that contains "Roboto":

@import url(http://fonts.googleapis.com/css?family=Roboto:500,500italic,400,400italic,300,300italic|Roboto+Condensed:400);

And here's my webpack.config.js:

{
  "entry":          {
                      "jsx":    [
                                  "node_modules/Ambidex/src/render.client.js",
                                  "webpack-dev-server/client?http://tardis.local:8078",
                                  "webpack/hot/dev-server"
                                ],

                      "styles": [
                                  "tardis/styles.scss",
                                  "webpack-dev-server/client?http://tardis.local:8078",
                                  "webpack/hot/dev-server"
                                ]
                    },

  "resolve":        {
                      "extensions": [
                        "",
                        ".js",
                        ".jsx",
                        ".scss"
                      ]
                    },

  "module":         {
                      "loaders":  [
                                    {
                                      "test":   /\.jsx?$/,
                                      "loader": "react-hot-loader!jsx-loader?harmony"
                                    },
                                    {
                                      "test":   /\.scss$/,
                                      "loader": "style-loader!css-loader!autoprefixer-loader!sass-loader"
                                    }
                                  ]
                    },

  "output":         {
                      "filename":       "[name].js",
                      "chunkFilename":  "chunk_[id].js",
                      "publicPath":     "http://tardis.local:8078/bundles/",
                      "pathinfo":       true,
                      "path":           "tardis/./bundles/"
                    },

  "plugins":        [
                      new Webpack.optimize.DedupePlugin(),
                      new Webpack.optimize.OccurenceOrderPlugin(),
                      new Webpack.HotModuleReplacementPlugin(),
                      new Webpack.DefinePlugin(
                        {
                          "__ambidexRoutesPath":  "\"tardis/routes.jsx\""
                        }
                      )
                    ],

  "context":        "node_modules/Ambidex/src",

  "resolveLoader":  {
                      "root":           "node_modules/Ambidex/node_modules"
                    }
}

Dependency graph and duplicated dependencies on build

I am trying to understand how I should require a sass dependency that is a requirement to more than one of my other modules. Something like normalize.scss (I am using the scss fork just for convenience). Which in theory should be a dependency of everything (since it should be loaded first).

Suppose I have two modules, maybe:

play-button.scss, which would have a dependency to normalize:

@import 'node_modules/normalize.scss';

.play-button {
  // its style
}

and another module: restart-game-screen.scss, which would also have a dependency to normalize:

@import 'node_modules/normalize.scss';

.restart-game-screen {
  // its style
}

Shouldn't the loader identify that the normalize.scss is used in two places and only bundle it once? It looks like this might not be supported right now by the way libsass works. If it doesn't, what is the best approach to handle these shared common modules?

Just to be clear, I usually organize my application`s component (Backbone or React) like:

  • player-button.scss
  • player-button.js

Each component has its own dependency graph. Meaning that at the JS file I have a requirement to the SCSS file.

An old solution to this problem is to have a 'manifest file': a single entry point for the entire application stylesheet that requires (@import) everything.

Error compiling .scss file

I am trying to compile .scss files using this loader.
I am getting the error below when I invoke webpack command:

Hash: 471ab211129c4252e031
Version: webpack 1.7.3
Time: 52ms
    + 1 hidden modules

ERROR in ./dummy.scss
Module parse failed: /home/chandu/www/sass-loader-test/node_modules/sass-loader/index.js!/home/chandu/www/sass-loader-test/dummy.scss Line 1: Unexpected token {
You may need an appropriate loader to handle this file type.
| body {
|   background-color: #fff; }
| 

I have created a repo to replicate the issue: https://github.com/Chandu/sass-loader-test

When I use node-sass directly I don't get any error. You can try this running node test.js from the repo linked above.

chandu@nobuntu:~/www/sass-loader-test$ node test.js 
body {
  background-color: #fff; }

Am pretty sure I am doing something wrong, but not sure what it is.
Can anyone help me with this?

Error on SASS Partials in 1.x

Hi @jhnns,

I am not a node-sass expert by any means, and so I cannot comment on exactly what the desired end result should be, but I make extensive use of SASS partials in my code and the handling of them seems to have changed when moving from 0.x to 1.x.

For example:
If I have file _my-partial.scss, I would expect to (as working in 0.x) be able to reference it in my main SCSS file as @import "my-partial".

In 1.x, you have to explicitly write the underscore, but as I understand it, the underscore is what signifies to SASS that it is indeed a partial.

More info: http://sass-lang.com/guide

Many thanks for your hard work on sass-loader!

James

Error when upgrading from 0.1.1 to 0.2.0

Hi,

I have upgraded and am getting the following error:

56% 38/49 build modulesgrunt(59323,0x7fff71003310) malloc: *** error for object 0x1074175a9: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

My working package.json is here:
https://github.com/RayPatterson/modulux/blob/master/package.json

This works with 0.1.1 but as soon as I upgrade I get the error even if I remove all SCSS files.

Any help would be appreciated.

Thanks,

Ray

webpack-dev-server breaking on sass error

Hi,

I am using sass-loader in webpack-dev-server mode.
If an sass error occurs webpack-dev-server is halting and not reacting to subsequent changes.
Is there any way to fix this problems ?

Thanks
Kiran

Ignore url()s import?

Is there a way I can tell sass-loader to ignore urls() states so that it doesn't try to import them?

@font-face {
font-family:'Myriad Set Pro';
font-style:normal;
font-weight:100;
src:url("../fonts/MYRIADPRO-REGULAR.OTF") format("OTF"), url("/resources/fonts/MYRIADPRO-REGULAR.OTF") format("truetype");
*src:url('');
}

ERROR in ./resources/fonts/MYRIADPRO-REGULAR.OTF
Module parse failed: /~/Developer/Project/resources/fonts/MYRIADPRO-REGULAR.OTF Line 1: Unexpected token ILLEGAL

Error when importing Compass

Hi,
If I add

@import 'compass'

to may sass file I get an error Module build failed when trying to compile the file.
Any thoughts?
Thanks

Error when upgrading from 0.1.1

Hi,

I just upgraded to 0.2.0 from 0.1.1 and I am getting the following error:

53% 38/52 build modulesAssertion failed: (val->IsString()), function _NanGetExternalParts, file ../node_modules/nan/nan.h, line 1725.
Abort trap: 6

Not much luck looking it up.

I'm using:
webpack 1.3.1-beta4
grunt-webpack 1.0.7
grunt-webpack-server 0.1.0
css-loader 0.6.12
style-loader 0.6.4
autoprefixer-loader 0.1.1

Any ideas?

Thanks!

Regression in 0.3.0

I just tried upgrading to 0.3.0 and got this error in code that works in 0.2.0:

./~/css-loader!./~/autoprefixer-loader!./~/sass-loader!./application/styles.scss
Module build failed: TypeError: undefined is not a function
    at resolveSassPath (node_modules/sass-loader/node_modules/sass-graph/sass-graph.js:24:23)
    at Graph.addFile (node_modules/sass-loader/node_modules/sass-graph/sass-graph.js:66:20)
    at Graph.addFile (node_modules/sass-loader/node_modules/sass-graph/sass-graph.js:72:12)
    at Graph.addFile (node_modules/sass-loader/node_modules/sass-graph/sass-graph.js:72:12)
    at Object.module.exports.parseFile (node_modules/sass-loader/node_modules/sass-graph/sass-graph.js:122:9)
    at Object.module.exports (node_modules/sass-loader/index.js:33:27)
 @ ./application/styles.scss 3:1-339 8:9-347

Error when requiring an empty .scss

Hi there!

First, thanks for this loader!

now, regarding the issue, it seems like requiring an empty .scss is raising the following:

node: ../node_modules/nan/nan.h:1725: bool _NanGetExternalParts(v8::Handle<v8::Value>, const char**, size_t*): Assertion `val->IsString()' failed.
[1]    2678 abort      webpack

It seems like it is something related to sass/node-sass#337

You may not @extend an outer selector from within @media.

Hello,
I'm trying to build bootstrap-sass with sass-loader, and i'm getting the following error:

ERROR in ./~/css-loader!./~/sass-loader?outputStyle=expanded&includePaths[]=/Users/....../node_modules!./app/stylesheets/main.scss
Module build failed:
    .input-group-sm & {
                                     ^
      You may not @extend an outer selector from within @media.
You may only @extend selectors within the same directive.
From "@extend .input-sm" on line 48 of node_modules/bootstrap-sass/assets/stylesheets/bootstrap/_input-groups.scss

      in /Users/jason/dev/goco-client/node_modules/bootstrap-sass/assets/stylesheets/bootstrap/_forms.scss (line 189, column 39)
 @ ./app/stylesheets/main.scss 4:14-284

My relevant npm versions:

Is this a known issue?

Looking for a maintainer for this repo

I notice some issues and PRs, but I recently don't have a lot of time left to maintain some OSprojects. Also, haven't used this loader in a while so i'm a bit off the project. Therefore i'm looking for someone who would like to maintain this project with me.

@cody? @akiran?@jhnns?

Error messages are obscure (much worse than ruby sass)

When compiling sass, the error messages are obscure:

ERROR in ../~/css-loader!../~/sass-loader?outputStyle=expanded!../app/assets/stylesheets/test-sass-stylesheet.scss
Module build failed:
 @ ../app/assets/stylesheets/test-sass-stylesheet.scss 3:1-279 8:9-287

It turns out that this error was from:

/* Proof of concept of loading css from webpack */

// partial defines the $comment-text-color
import "test-sass-stylesheet-partial";

Note the lack of an @ before the import. And that was on line 4. So other than
the error saying which file has the error, it doesn't tell you much.

The Ruby error is way better:

Sass::SyntaxError (Invalid CSS after "...esheet-partial"": expected "{", was ";"
  (in /Users/justin/j/react/react-rails-tutorial/app/assets/stylesheets/application.css.scss:4)):
  app/assets/stylesheets/test-sass-stylesheet.scss:4
  app/assets/stylesheets/application.css.scss:4
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__3489044243874918414_70294421247320'

Relative URLs are funky

I'm not sure if this issue is a) not specifically to do with sass-loader, or b) already described in another issue, but hopefully this will at the very least enlighten me or others with the same issue. Apologies if it has been covered or I'm looking in the wrong place.

Given the following directory structure:

- fonts/
-- font-file.woff
- css/
-- app.css (build target)
- scss/
-- app.scss
-- partials/
---- _i-load-a-font.scss

app.scss:

@import "partials/i-load-a-font"

partials/i-load-a-font.scss:

@font-face{
  src: url("../fonts/font-file.woff")
}

If we build scss/app.scss to css/app.css, the font path is correct - that is how SASS expects the path to resolve - as it resolves it based on the final output CSS. If we use webpack with sass-loader, this breaks, because it tries to find the font-file.woff relative to partials/i-load-a-font.scss.

So I've inherited a project that is compiled with SASS that compiles properly with grunt or whatever they used, but as soon as I try to compile it with webpack it won't work. Is there a way to get this to work with webpack? It would seem odd to me that we would have to rewrite the SASS for this reason.

errors crash webpack, even in --debug mode

The other loaders that I've tried right now display an error message gracefully in debug mode. With sass loader i get a message like

    throw err;
          ^
source string:2: error: file to import not found or unreadable: "variables"```

node-sass ^3.0.0-alpha.0 is not stable

error message:
node: ../deps/uv/src/unix/core.c:171: uv__finish_close: Assertionhandle->flags & UV_CLOSING' failed.`

Then I tried to install an old version of node-sass by npm install node-sass, but come out this error message:

npm ERR! peerinvalid The package node-sass does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants node-sass@^3.0.0-alpha.0

Maybe you can change the version number of node-sass to *, so I can specify the required version of node-sass.

[Question] source-maps with css or sass?

Hi,

I am using sass-loader to compile sass code. Can we have the source-map to trace back the source file with webpack for sass?

Currently, I setup Sass-loader by

 { test: /\.scss/, loader: "style-loader!sass-loader?outputStyle=expanded" },

with

    cache: true,
    debug: true,
    devtool: 'source-map',
    'output-pathinfo': true,

Is it possible to trace back the source sass file in chrome dev tools?

Getting contents without loading

I'm wanting to be able to get the contents within JS I can use css-loader I know and that passes me back an array with a nested array which doesn't feel very nice as a small change could quite easily break that.

Can you think of anything to be able to get the contents straight away because I am wanting to do my own loading without having to use style-loader?

problem with keyframes

I have the following code in my scss file:

@Keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 0 -166px; }
}

When the sass loader runs, it fails with the message:
Module build failed: Error: Please check the validity of the CSS block starting from the line #7656

Also, the line numbers are not accurate which makes it very difficult to debug. Is there an way to run the loader from the command line so I can see the direct output?

Update to Node SASS 2.0.1

Looks like both grunt and gulp sass have updated their version of node-sass. Could you please update the loader?

SCSS build error

Hi,

I'm getting an error with a specific SCSS file: https://github.com/danielguillan/bem-constructor

'Module build failed:
$e: #{&}#{$bem-element-separator}#{$element};
^
Error reading values after
in /playground/app/styles/settings/_ben-constructor.scss (line 475, column 13)
@ ./app/styles/main.scss 4:14-225'

Seems to work fine with other scss compilers.

What am I doing wrong?

Just pulled v1.0.0 and get an error

I'm getting this error:

Assertion failed: (handle->flags & UV_CLOSING), function uv__finish_close, file ../deps/uv/src/unix/core.c, line 171.

I'm going to try reverting to the prior version to see if that fixes the issue.

After going to this version: "^0.4.0-beta.1", the error goes away.

I'm seeing other issues after updating all modules. I'll post an update shortly.

Just ran

npm i --save-dev node-sass

and went back to 1.0.0

and the prior error went away. Still some other issues, but might be unrelated.

move node-sass to peerDependencies?

Hi, as node-sass currently have some issue with pre-build binaries, I'm wondering that if you have plan to move node-sass to peerDependencies instead of dependencies?

This will allow client to override custom node-sass version without fork the sass-loader project. Just specify "node-sass": "1.0.3" in their package.json and it will load the desired version of node-sass.

Abort trap: 6

After upgrading to 1.0.0 I'm getting fairly inconsistent errors along the lines of:

Assertion failed: (handle->flags & UV_CLOSING), function uv__finish_close, file ../deps/uv/src/unix/core.c, line 171.
Abort trap: 6

Seems to be an issue with node-sass that has persisted into the pre-release sass-loader is using?

sass/node-sass#713

How do I import bootstrap-sass?

added this stuff to webpack loaders:

    {test: /\.scss/, loader: 'style!css!sass?includePaths[]=' +
        (path.resolve(__dirname, "./node_modules"))},
    {test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
    {test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }

and in my scss:
@import "bootstrap-sass/assets/stylesheets/_bootstrap.scss";

But I get bunch of errors resolving the relative paths with bootstrap-sass

ERROR in .//css-loader!.//sass-loader?includePaths[]=/Users/kharriger/code/webpack-template/node_modules!./src/sass/all.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ../fonts/bootstrap/glyphicons-halflings-regular.eot in /Users/kharriger/code/webpack-template/src/sass
@ .//css-loader!.//sass-loader?includePaths[]=/Users/kharriger/code/webpack-template/node_modules!./src/sass/all.scss 2:3068-3130 2:3144-3206

ERROR in .//css-loader!.//sass-loader?includePaths[]=/Users/kharriger/code/webpack-template/node_modules!./src/sass/all.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ../fonts/bootstrap/glyphicons-halflings-regular.woff in /Users/kharriger/code/webpack-template/src/sass
@ .//css-loader!.//sass-loader?i

I've installed yesterday and worked, installed today and doesn't work

I've installed with npm install sass-loader.

I've noticed that in the package.json there are some diff.

Of today (that doesn't work):

"_from": "sass-loader@",
"readme": "ERROR: No README data found!"

Of yesterday (that works):

"_from": "sass-loader@^0.3.1",

So no readme error and added ^0.3.1.

With the today's version I get:

Error: `libsass` bindings not found. Try reinstalling `node-sass`?
node_modules\sass-loader\node_modules\node-sass\lib\index.js:21:11

With yesterday's version I get this error:

Error: ENOENT, open 'E:\a\dist\E:\a\node_modules\extract-text-webpack-plugin E:\a\node_modules\css-loader\index.js!E:\a\node_modules\sass-loader\index.js'

Why is messing this up?

My webpack config for scss is like this:

        {
            test: /\.css$/,
            loader: ExtractTextPlugin.extract("style", "css")
        },
        {
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract("style", "css!sass")
        },

Ok, strange again, this happens in all my npm modules that were installed today vs yesterday...

Well, these are not the only changes now that I'm diff, I will put now them here:

updating...

Segmentation fault

I get a segmentation fault and the dev server crashes when modifying a watched file. On the initial compilation it works fine.
I think it could be related to upgrading to node-sass 1.0.1 because downgrading to prior version of sass-loader it works just fine...
It also seems that some imported styles don't get bundled (foundation's components in my case).

[Question] Compass with sass-loader?

I would like to use sass with compass through webpack. Any plans on supporting this in sass-loader, or ideas on how to achieve it in general?

Marked dependencies do not respect previous loaders in the pipe

Let's say main.scss has @import 'some-settings.scss' at the top. We have another loader that replaces 'some-settings.scss' with '/path/to/our/specific/settings-file.scss'. It compiles just fine, but the marked dependencies are incorrect. This is because sass-graph is used to mark dependencies from the original source file, ignoring the actual piped content, but node-sass is used to compile the sass from the piped content.

So the thing that marks the dependencies is marking them based off incorrect, "out-of-date" data. It should mark them based off the content parameter in the loader, not by reading in the file contents.

Uglify thinks style is dead code

I noticed that my webfont files were not getting copied over when I was using:

plugins: [new webpack.optimize.UglifyJsPlugin()]

It gave me:

Dropping unreachable code [./~/style-loader!./~/css-loader!./~/sass-loader!./client/components/Dropdown.scss:6,0]

Turning off uglify solved the issue but ultimately I would like to minify code.

example for using with node-bourbon

Hi @jtangelder While trying to use the loader with node-bourbon,

var bourbon = require('node-bourbon').includePaths;

module.exports = {
  entry: './src/js/main.js',
  output: {
    path: './build',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.json$/, loader: 'json' },
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      { test: /\.png/, loader: 'url-loader?limit=100000&mimetype=image/png' },
      { test: /\.scss$/, loader: "style!css!sass?includePaths[]=" + bourbon},
      { test: /\.js$/, loader: "jsx-loader" }
    ]
  },
  resolve: {
    modulesDirectories: ['node_modules'],
    extensions: ['', '.js', '.json']
  }
}

I got the following error:

➜  csviz git:(webpack) ✗ webpack
Hash: 42199728e42c6181b5ac
Version: webpack 1.4.0-beta10
Time: 6505ms
    Asset     Size  Chunks             Chunk Names
bundle.js  1620446       0  [emitted]  main
    + 329 hidden modules

ERROR in ./~/css-loader!./~/sass-loader?includePaths[]=/Users/fraserxu/projects/csviz/~/node-bourbon/assets/stylesheets!./src/scss/main.scss
Module build failed:
 @ ./src/scss/main.scss 4:14-296

Because the includePaths is an array, so I'm wondering whether it's because the way I write it is wrong.

Can you help me figure it out or you could give an example with using with node-bourbon.

I thought it maybe useful because many people will use node-bourbon in their project.

Thanks.

Use custom importer

Just wanted to point out that custom importers have been implemented with sass/libsass#21. They are currently being tested and it will take some time until node-sass provides an api, so it's still a way to go.

With custom importers we're able to plug-in webpack's resolving algorithm.

preventing duplicated imports

Hi, we're trying to keep things completely modular and have each component declaratively import everything it needs. This causes things to be put into style.css multiple times (using extractTextPlugin), giving us a huge css file.

Is there any way of preventing this? I tried using scss-only hacks, like in https://github.com/zurb/foundation/blob/1a45d92be8af20bf6b3e8d28c12fdbc853205cce/scss/foundation/_functions.scss , but because sass loader is running node-sass afresh each scss that's required, the map in sass is not persisted.

Support indented syntax

node-sass now supports indented syntax, but sass-loader seems to expect scss style syntax.

Support for media queries

The current version seems to break when the sass file contains media queries.
ERROR in .//css-loader!.//sass-loader!./src/styles/responsive.scss
Module build failed: Error: Please check the validity of the CSS block starting from the line #2175

@font-face URLs not resolved

The loader doesn't seem to resolve @font-face URLs. I'm trying to @import "bootstrap-sass/assets/stylesheets/bootstrap"; from the bootstrap-sass npm package, and getting the following error:

ERROR in ./~/css-loader!./~/sass-loader?includePaths[]=./bower_components&includePaths[]=./node_modules!./src/styles/app.scss
Module not found: Error: Cannot resolve file or directory ./bootstrap/glyphicons-halflings-regular.eot in /home/charles/projects/react/src/styles
 @ ./~/css-loader!./~/sass-loader?includePaths[]=./bower_components&includePaths[]=./node_modules!./src/styles/app.scss 2:2989-3044 2:3058-3113

"ModuleBuildError: Module build failed" error

I am getting this error from this file:

at DependenciesBlock.onModuleBuildFailed (./node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:288:19)

I tried with both version 0.3.1 and the version from master branch. Any ideas what might be happening?

sourceMappingUrl is wrong

I nearly got source maps to work, but it's outputting the wrong sourceMappingUrl. I am getting ../../..//build/sass.map instead of styles.css.map. I am using sass-loader 0.4.1, webpack 1.4.15 and extract-text-webpack-plugin 0.3.8.

This is my configuration:

var webPackConfig = {
    output: {
        path: path.join(__dirname, "build"),
        filename: "bundle.js"
    },

    entry: "./src/main.js",
    debug: true,
    devtool: "source-map",

    module: {
        loaders: [
            { test: /\.gif/, loader: "url?limit=10000&minetype=image/gif" },
            { test: /\.jpg/, loader: "url?limit=10000&minetype=image/jpg" },
            { test: /\.png/, loader: "url?limit=10000&minetype=image/png" },
            { test: /\.js$/, loader: "jsx" },
            { test: /\.json$/, loader: "json" },
            { test: /\.woff$/, loader: "url?limit=10000&minetype=application/font-woff" },
            { test: /\.ttf$/, loader: "file" },
            { test: /\.eot$/, loader: "file" },
            { test: /\.svg$/, loader: "file" },
            { test: /\.css/, loader: ExtractTextPlugin.extract("css?sourceMap") },
            { test: /\.scss$/, loader: ExtractTextPlugin.extract(
                "css?sourceMap" +
                "!sass?sourceMap&sourceMapContents=true" +
                "&outputStyle=expanded" +
                "&includePaths[]=" + require("node-bourbon").includePaths +
                "&includePaths[]=" + (path.resolve(__dirname, "./node_modules"))
            )}
        ],
        noParse: /parse-latest.js/
    },

    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(),
        new ExtractTextPlugin("styles.css")
    ],

    resolve: {
        modulesDirectories: ['node_modules'],
        extensions: ['', '.js', '.json']
    }
}

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.