sass-loader 6.0.7 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,55 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="7.0.3"></a>
6
+ ## [7.0.3](https://github.com/webpack-contrib/sass-loader/compare/v7.0.2...v7.0.3) (2018-06-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Bare imports not working sometimes (#579) ([c348281](https://github.com/webpack-contrib/sass-loader/commit/c348281)), closes [#566](https://github.com/webpack-contrib/sass-loader/issues/566)
12
+
13
+
14
+
15
+ <a name="7.0.2"></a>
16
+ ## [7.0.2](https://github.com/webpack-contrib/sass-loader/compare/v7.0.1...v7.0.2) (2018-06-02)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * Errors being swallowed when trying to load node-sass (#576) ([6dfb274](https://github.com/webpack-contrib/sass-loader/commit/6dfb274)), closes [#563](https://github.com/webpack-contrib/sass-loader/issues/563)
22
+ * Report error to user for problems loading node-sass (#562) ([2529c07](https://github.com/webpack-contrib/sass-loader/commit/2529c07))
23
+
24
+
25
+
26
+ <a name="7.0.1"></a>
27
+ ## [7.0.1](https://github.com/webpack-contrib/sass-loader/compare/v7.0.0...v7.0.1) (2018-04-13)
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * Wrong import precedence (#557) ([f4eeff1](https://github.com/webpack-contrib/sass-loader/commit/f4eeff1))
33
+
34
+
35
+
36
+ <a name="7.0.0"></a>
37
+ # [7.0.0](https://github.com/webpack-contrib/sass-loader/compare/v6.0.7...v7.0.0) (2018-04-13)
38
+
39
+
40
+ ### Features
41
+
42
+ * Refactor resolving and simplify webpack config aliases (#479) ([e0fde1a](https://github.com/webpack-contrib/sass-loader/commit/e0fde1a))
43
+ * Remove `node-sass` from `peerDependencies` (#533) ([6439cef](https://github.com/webpack-contrib/sass-loader/commit/6439cef))
44
+
45
+
46
+ ### BREAKING CHANGES
47
+
48
+ * Drop official node 4 support
49
+ * This slightly changes the resolving algorithm. Should not break in normal usage, but might break in complex configurations.
50
+ * The sass-loader throws an error at runtime now and refuses to compile if the peer dependency is wrong. This could break applications where npm's peer dependency warning was just ignored.
51
+
52
+
53
+
5
54
  <a name="6.0.7"></a>
6
55
  ## [6.0.7](https://github.com/webpack-contrib/sass-loader/compare/v6.0.6...v6.0.7) (2018-03-03)
7
56
 
package/README.md CHANGED
@@ -14,11 +14,11 @@
14
14
  <img width="200" height="200"
15
15
  src="https://webpack.js.org/assets/icon-square-big.svg">
16
16
  </a>
17
- <h1>SASS Loader</h1>
18
- <p>Loads a SASS/SCSS file and compiles it to CSS.</p>
17
+ <h1>Sass Loader</h1>
18
+ <p>Loads a Sass/SCSS file and compiles it to CSS.</p>
19
19
  </div>
20
20
 
21
- Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-loader](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract it into a separate file.
21
+ Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-loader](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract it into a separate file.
22
22
  Looking for the webpack 1 loader? Check out the [archive/webpack-1 branch](https://github.com/webpack-contrib/sass-loader/tree/archive/webpack-1).
23
23
 
24
24
  <h2 align="center">Install</h2>
@@ -45,13 +45,11 @@ module.exports = {
45
45
  module: {
46
46
  rules: [{
47
47
  test: /\.scss$/,
48
- use: [{
49
- loader: "style-loader" // creates style nodes from JS strings
50
- }, {
51
- loader: "css-loader" // translates CSS into CommonJS
52
- }, {
53
- loader: "sass-loader" // compiles Sass to CSS
54
- }]
48
+ use: [
49
+ "style-loader", // creates style nodes from JS strings
50
+ "css-loader", // translates CSS into CommonJS
51
+ "sass-loader" // compiles Sass to CSS
52
+ ]
55
53
  }]
56
54
  }
57
55
  };
@@ -85,34 +83,31 @@ See [node-sass](https://github.com/andrew/node-sass) for all available Sass opti
85
83
 
86
84
  ### In production
87
85
 
88
- Usually, it's recommended to extract the style sheets into a dedicated file in production using the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin). This way your styles are not dependent on JavaScript:
86
+ Usually, it's recommended to extract the style sheets into a dedicated file in production using the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin). This way your styles are not dependent on JavaScript:
89
87
 
90
88
  ```js
91
- const ExtractTextPlugin = require("extract-text-webpack-plugin");
92
-
93
- const extractSass = new ExtractTextPlugin({
94
- filename: "[name].[contenthash].css",
95
- disable: process.env.NODE_ENV === "development"
96
- });
89
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
97
90
 
98
91
  module.exports = {
99
92
  ...
100
93
  module: {
101
94
  rules: [{
102
95
  test: /\.scss$/,
103
- use: extractSass.extract({
104
- use: [{
105
- loader: "css-loader"
106
- }, {
107
- loader: "sass-loader"
108
- }],
109
- // use style-loader in development
110
- fallback: "style-loader"
111
- })
96
+ use: [
97
+ // fallback to style-loader in development
98
+ process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader,
99
+ "css-loader",
100
+ "sass-loader"
101
+ ]
112
102
  }]
113
103
  },
114
104
  plugins: [
115
- extractSass
105
+ new MiniCssExtractPlugin({
106
+ // Options similar to the same options in webpackOptions.output
107
+ // both options are optional
108
+ filename: "[name].css",
109
+ chunkFilename: "[id].css"
110
+ })
116
111
  ]
117
112
  };
118
113
  ```
@@ -1,58 +1,60 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require("path");
4
+ const utils = require("loader-utils");
4
5
 
5
- // libsass uses this precedence when importing files without extension
6
- const extPrecedence = [".scss", ".sass", ".css"];
6
+ const matchModuleImport = /^~([^\/]+|@[^\/]+[\/][^\/]+)$/;
7
7
 
8
8
  /**
9
9
  * When libsass tries to resolve an import, it uses a special algorithm.
10
10
  * Since the sass-loader uses webpack to resolve the modules, we need to simulate that algorithm. This function
11
- * returns an array of import paths to try.
11
+ * returns an array of import paths to try. The last entry in the array is always the original url
12
+ * to enable straight-forward webpack.config aliases.
12
13
  *
13
- * @param {string} request
14
+ * @param {string} url
14
15
  * @returns {Array<string>}
15
16
  */
16
- function importsToResolve(request) {
17
+ function importsToResolve(url) {
18
+ const request = utils.urlToRequest(url);
19
+ // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
20
+ // @see https://github.com/webpack-contrib/sass-loader/issues/167
21
+ const ext = path.extname(request);
22
+
23
+ if (matchModuleImport.test(url)) {
24
+ return [request, url];
25
+ }
26
+
17
27
  // libsass' import algorithm works like this:
18
- // In case there is no file extension...
19
- // - Prefer modules starting with '_'.
20
- // - File extension precedence: .scss, .sass, .css.
28
+
21
29
  // In case there is a file extension...
22
30
  // - If the file is a CSS-file, do not include it all, but just link it via @import url().
23
31
  // - The exact file name must match (no auto-resolving of '_'-modules).
32
+ if (ext === ".css") {
33
+ return [];
34
+ }
35
+ if (ext === ".scss" || ext === ".sass") {
36
+ return [request, url];
37
+ }
24
38
 
25
- // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
26
- // @see https://github.com/webpack-contrib/sass-loader/issues/167
27
- const ext = path.extname(request);
39
+ // In case there is no file extension...
40
+ // - Prefer modules starting with '_'.
41
+ // - File extension precedence: .scss, .sass, .css.
28
42
  const basename = path.basename(request);
29
- const dirname = path.dirname(request);
30
- const startsWithUnderscore = basename.charAt(0) === "_";
31
- const hasCssExt = ext === ".css";
32
- const hasSassExt = ext === ".scss" || ext === ".sass";
33
-
34
- // a module import is an identifier like 'bootstrap-sass'
35
- // We also need to check for dirname since it might also be a deep import like 'bootstrap-sass/something'
36
- let isModuleImport = request.charAt(0) !== "." && dirname === ".";
37
-
38
- if (dirname.charAt(0) === "@") {
39
- // Check whether it is a deep import from scoped npm package
40
- // (i.e. @pkg/foo/file), if so, process import as file import;
41
- // otherwise, if we import from root npm scoped package (i.e. @pkg/foo)
42
- // process import as a module import.
43
- isModuleImport = !(dirname.indexOf("/") > -1);
43
+
44
+ if (basename.charAt(0) === "_") {
45
+ return [
46
+ `${ request }.scss`, `${ request }.sass`, `${ request }.css`,
47
+ url
48
+ ];
44
49
  }
45
50
 
46
- return (isModuleImport && [request]) || // Do not modify module imports
47
- (hasCssExt && []) || // Do not import css files
48
- (hasSassExt && [request]) || // Do not modify imports with explicit extensions
49
- (startsWithUnderscore ? [] : extPrecedence) // Do not add underscore imports if there is already an underscore
50
- .map(ext => "_" + basename + ext)
51
- .concat(
52
- extPrecedence.map(ext => basename + ext)
53
- ).map(
54
- file => dirname + "/" + file // No path.sep required here, because imports inside SASS are usually with /
55
- );
51
+ const dirname = path.dirname(request);
52
+
53
+ return [
54
+ `${ dirname }/_${ basename }.scss`, `${ dirname }/_${ basename }.sass`, `${ dirname }/_${ basename }.css`,
55
+ `${ request }.scss`, `${ request }.sass`, `${ request }.css`,
56
+ url
57
+ ];
56
58
  }
57
59
 
58
60
  module.exports = importsToResolve;
package/lib/loader.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- const sass = require("node-sass");
4
3
  const path = require("path");
5
4
  const async = require("neo-async");
6
5
  const formatSassError = require("./formatSassError");
@@ -12,7 +11,7 @@ const pify = require("pify");
12
11
  // fs tasks when running the custom importer code.
13
12
  // This can be removed as soon as node-sass implements a fix for this.
14
13
  const threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4;
15
- const asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1);
14
+ let asyncSassJobQueue = null;
16
15
 
17
16
  /**
18
17
  * The sass-loader makes node-sass available to webpack modules.
@@ -21,6 +20,19 @@ const asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1);
21
20
  * @param {string} content
22
21
  */
23
22
  function sassLoader(content) {
23
+ if (asyncSassJobQueue === null) {
24
+ const sass = require("node-sass");
25
+ const sassVersion = /^(\d+)/.exec(require("node-sass/package.json").version).pop();
26
+
27
+ if (Number(sassVersion) < 4) {
28
+ throw new Error(
29
+ "The installed version of `node-sass` is not compatible (expected: >= 4, actual: " + sassVersion + ")."
30
+ );
31
+ }
32
+
33
+ asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1);
34
+ }
35
+
24
36
  const callback = this.async();
25
37
  const isSync = typeof callback !== "function";
26
38
  const self = this;
@@ -17,7 +17,6 @@
17
17
  */
18
18
 
19
19
  const path = require("path");
20
- const utils = require("loader-utils");
21
20
  const tail = require("lodash.tail");
22
21
  const importsToResolve = require("./importsToResolve");
23
22
 
@@ -63,7 +62,7 @@ function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
63
62
  return (url, prev, done) => {
64
63
  startResolving(
65
64
  dirContextFrom(prev),
66
- importsToResolve(utils.urlToRequest(url))
65
+ importsToResolve(url)
67
66
  ) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
68
67
  .catch(() => ({ file: url }))
69
68
  .then(done);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sass-loader",
3
- "version": "6.0.7",
3
+ "version": "7.0.3",
4
4
  "description": "Sass loader for webpack",
5
5
  "author": "J. Tangelder",
6
6
  "license": "MIT",
@@ -40,21 +40,22 @@
40
40
  "eslint-plugin-jsdoc": "^2.4.0",
41
41
  "file-loader": "^0.11.2",
42
42
  "mocha": "^3.0.2",
43
+ "mock-require": "^3.0.1",
43
44
  "node-sass": "^4.5.0",
44
45
  "nyc": "^11.0.2",
45
46
  "raw-loader": "^0.5.1",
46
47
  "should": "^11.2.0",
47
48
  "standard-version": "^4.2.0",
48
49
  "style-loader": "^0.18.2",
50
+ "webpack": "^4.5.0",
49
51
  "webpack-dev-server": "^2.4.1",
50
52
  "webpack-merge": "^4.0.0"
51
53
  },
52
54
  "engines": {
53
- "node": ">= 4.3 < 5.0.0 || >= 5.10"
55
+ "node": ">= 6.9.0 || >= 8.9.0"
54
56
  },
55
57
  "peerDependencies": {
56
- "node-sass": "^4.0.0",
57
- "webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
58
+ "webpack": "^3.0.0 || ^4.0.0"
58
59
  },
59
60
  "keywords": [
60
61
  "sass",