Skip to content

Commit

Permalink
refactor: code (#833)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: when the `sourceMap` is `true`, `sassOptions.sourceMap`, `sassOptions.sourceMapContents`, `sassOptions.sourceMapEmbed`, `sassOptions.sourceMapRoot` and `sassOptions.omitSourceMapUrl` will be ignored.
  • Loading branch information
evilebottnawi committed Apr 16, 2020
1 parent 68dd278 commit f892eba
Show file tree
Hide file tree
Showing 5 changed files with 1,473 additions and 239 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -252,9 +252,9 @@ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://g

> ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
> ℹ️ Options such as `file` and `outFile` are unavailable.
> ℹ️ Options such as `data` and `file` are unavailable and will be ignored.
> ℹ We recommend not to use the `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because `sass-loader` automatically sets these options.
> ℹ We recommend not to set the `outFile`, `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because `sass-loader` automatically sets these options when the `sourceMap` option is `true`.
There is a slight difference between the `sass` (`dart-sass`) and `node-sass` options.

Expand Down Expand Up @@ -411,7 +411,10 @@ Default: depends on the `compiler.devtool` value

Enables/Disables generation of source maps.

By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option. All values enable source map generation except `eval` and `false` value.
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/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**

Expand Down
25 changes: 5 additions & 20 deletions src/getSassOptions.js
Expand Up @@ -73,9 +73,6 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
? loaderOptions.sourceMap
: loaderContext.sourceMap;

// opt.sourceMap
// Not using the `this.sourceMap` flag because css source maps are different
// @see https://github.com/webpack/css-loader/pull/40
if (useSourceMap) {
// Deliberately overriding the sourceMap option here.
// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
Expand All @@ -84,22 +81,10 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
// all paths in sourceMap.sources will be relative to that path.
// Pretty complicated... :(
options.sourceMap = path.join(process.cwd(), '/sass.map');

if ('sourceMapRoot' in options === false) {
options.sourceMapRoot = process.cwd();
}

if ('omitSourceMapUrl' in options === false) {
// The source map url doesn't make sense because we don't know the output path
// The css-loader will handle that for us
options.omitSourceMapUrl = true;
}

if ('sourceMapContents' in options === false) {
// If sourceMapContents option is not set, set it to true otherwise maps will be empty/null
// when exported by webpack-extract-text-plugin.
options.sourceMapContents = true;
}
options.sourceMapRoot = process.cwd();
options.sourceMapContents = true;
options.omitSourceMapUrl = true;
options.sourceMapEmbed = false;
}

const { resourcePath } = loaderContext;
Expand All @@ -109,7 +94,7 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
if (
ext &&
ext.toLowerCase() === '.sass' &&
'indentedSyntax' in options === false
typeof options.indentedSyntax === 'undefined'
) {
options.indentedSyntax = true;
} else {
Expand Down

0 comments on commit f892eba

Please sign in to comment.