css-loader 0.28.4 → 0.28.8

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,48 @@
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="0.28.8"></a>
6
+ ## [0.28.8](https://github.com/webpack-contrib/css-loader/compare/v0.28.7...v0.28.8) (2018-01-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **loader:** correctly check if source map is `undefined` ([#641](https://github.com/webpack-contrib/css-loader/issues/641)) ([0dccfa9](https://github.com/webpack-contrib/css-loader/commit/0dccfa9))
12
+ * proper URL escaping and wrapping (`url()`) ([#627](https://github.com/webpack-contrib/css-loader/issues/627)) ([8897d44](https://github.com/webpack-contrib/css-loader/commit/8897d44))
13
+
14
+
15
+
16
+ <a name="0.28.7"></a>
17
+ ## [0.28.7](https://github.com/webpack/css-loader/compare/v0.28.6...v0.28.7) (2017-08-30)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * pass resolver to `localsLoader` (`options.alias`) ([#601](https://github.com/webpack/css-loader/issues/601)) ([8f1b57c](https://github.com/webpack/css-loader/commit/8f1b57c))
23
+
24
+
25
+
26
+ <a name="0.28.6"></a>
27
+ ## [0.28.6](https://github.com/webpack/css-loader/compare/v0.28.5...v0.28.6) (2017-08-30)
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * add support for aliases starting with `/` (`options.alias`) ([#597](https://github.com/webpack/css-loader/issues/597)) ([63567f2](https://github.com/webpack/css-loader/commit/63567f2))
33
+
34
+
35
+
36
+ <a name="0.28.5"></a>
37
+ ## [0.28.5](https://github.com/webpack/css-loader/compare/v0.28.4...v0.28.5) (2017-08-17)
38
+
39
+
40
+ ### Bug Fixes
41
+
42
+ * match mutliple dashes (`options.camelCase`) ([#556](https://github.com/webpack/css-loader/issues/556)) ([1fee601](https://github.com/webpack/css-loader/commit/1fee601))
43
+ * stricter `[@import](https://github.com/import)` tolerance ([#593](https://github.com/webpack/css-loader/issues/593)) ([2e4ec09](https://github.com/webpack/css-loader/commit/2e4ec09))
44
+
45
+
46
+
5
47
  <a name="0.28.4"></a>
6
48
  ## [0.28.4](https://github.com/webpack/css-loader/compare/v0.28.3...v0.28.4) (2017-05-30)
7
49
 
package/README.md CHANGED
@@ -27,7 +27,7 @@ The `css-loader` interprets `@import` and `url()` like `import/require()`
27
27
  and will resolve them.
28
28
 
29
29
  Good loaders for requiring your assets are the [file-loader](https://github.com/webpack/file-loader)
30
- and the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see [below](https://github.com/michael-ciniawsky/css-loader#assets)).
30
+ and the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see [below](https://github.com/webpack-contrib/css-loader#assets)).
31
31
 
32
32
  **file.js**
33
33
  ```js
@@ -94,15 +94,16 @@ It's useful when you, for instance, need to post process the CSS as a string.
94
94
 
95
95
  |Name|Type|Default|Description|
96
96
  |:--:|:--:|:-----:|:----------|
97
- |**`root`**|`{String}`|`/`|Path to resolve URLs, URLs starting with `/` will not be translated|
98
- |**`url`**|`{Boolean}`|`true`| Enable/Disable `url()` handling|
99
- |**`alias`**|`{Object}`|`{}`|Create aliases to import certain modules more easily|
100
- |**`import`** |`{Boolean}`|`true`| Enable/Disable @import handling|
101
- |**`modules`**|`{Boolean}`|`false`|Enable/Disable CSS Modules|
102
- |**`minimize`**|`{Boolean\|Object}`|`false`|Enable/Disable minification|
103
- |**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
104
- |**`camelCase`**|`{Boolean\|String}`|`false`|Export Classnames in CamelCase|
105
- |**`importLoaders`**|`{Number}`|`0`|Number of loaders applied before CSS loader|
97
+ |**[`root`](#root)**|`{String}`|`/`|Path to resolve URLs, URLs starting with `/` will not be translated|
98
+ |**[`url`](#url)**|`{Boolean}`|`true`| Enable/Disable `url()` handling|
99
+ |**[`alias`](#alias)**|`{Object}`|`{}`|Create aliases to import certain modules more easily|
100
+ |**[`import`](#import)** |`{Boolean}`|`true`| Enable/Disable @import handling|
101
+ |**[`modules`](#modules)**|`{Boolean}`|`false`|Enable/Disable CSS Modules|
102
+ |**[`minimize`](#minimize)**|`{Boolean\|Object}`|`false`|Enable/Disable minification|
103
+ |**[`sourceMap`](#sourcemap)**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
104
+ |**[`camelCase`](#camelcase)**|`{Boolean\|String}`|`false`|Export Classnames in CamelCase|
105
+ |**[`importLoaders`](#importloaders)**|`{Number}`|`0`|Number of loaders applied before CSS loader|
106
+ |**`localIdentName`**|`{String}`|`[hash:base64]`|Configure the generated ident|
106
107
 
107
108
  ### `root`
108
109
 
@@ -140,7 +141,7 @@ url(~module/image.png) => require('module/image.png')
140
141
 
141
142
  Rewrite your urls with alias, this is useful when it's hard to change url paths of your input files, for example, when you're using some css / sass files in another package (bootstrap, ratchet, font-awesome, etc.).
142
143
 
143
- `css-loader`'s `alias` follows the same syntax as webpack's `resolve.alias`, you can see the details at the [resolve docs] (https://webpack.js.org/configuration/resolve/#resolve-alias)
144
+ `css-loader`'s `alias` follows the same syntax as webpack's `resolve.alias`, you can see the details at the [resolve docs](https://webpack.js.org/configuration/resolve/#resolve-alias)
144
145
 
145
146
  **file.scss**
146
147
  ```css
@@ -342,7 +343,7 @@ To import from multiple modules use multiple `composes:` rules.
342
343
 
343
344
  By default the css-loader minimizes the css if specified by the module system.
344
345
 
345
- In some cases the minification is destructive to the css, so you can provide your own options to the minifier if needed. cssnano is used for minification and you find a [list of options here](http://cssnano.co/options/).
346
+ In some cases the minification is destructive to the css, so you can provide your own options to the cssnano-based minifier if needed. See [cssnano's documentation](http://cssnano.co/guides/) for more information on the available options.
346
347
 
347
348
  You can also disable or enforce minification with the `minimize` query parameter.
348
349
 
@@ -418,7 +419,7 @@ The query parameter `importLoaders` allows to configure how many loaders before
418
419
  {
419
420
  loader: 'css-loader',
420
421
  options: {
421
- importLoaders: 1 // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
422
+ importLoaders: 2 // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
422
423
  }
423
424
  },
424
425
  'postcss-loader',
@@ -487,7 +488,6 @@ module.exports = {
487
488
  })
488
489
  ]
489
490
  : []
490
- ]
491
491
  }
492
492
  ```
493
493
 
@@ -1,7 +1,7 @@
1
1
  var camelCase = require("lodash.camelcase");
2
2
 
3
3
  function dashesCamelCase(str) {
4
- return str.replace(/-(\w)/g, function(match, firstLetter) {
4
+ return str.replace(/-+(\w)/g, function(match, firstLetter) {
5
5
  return firstLetter.toUpperCase();
6
6
  });
7
7
  }
package/lib/loader.js CHANGED
@@ -42,6 +42,7 @@ module.exports = function(content, map) {
42
42
  from: loaderUtils.getRemainingRequest(this).split("!").pop(),
43
43
  to: loaderUtils.getCurrentRequest(this).split("!").pop(),
44
44
  query: query,
45
+ resolve: resolve,
45
46
  minimize: this.minimize,
46
47
  loaderContext: this,
47
48
  sourceMap: sourceMap
@@ -82,7 +83,13 @@ module.exports = function(content, map) {
82
83
  }
83
84
 
84
85
  cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
85
- if(query.url !== false) {
86
+
87
+ // helper for ensuring valid CSS strings from requires
88
+ var urlEscapeHelper = "";
89
+
90
+ if(query.url !== false && result.urlItems.length > 0) {
91
+ urlEscapeHelper = "var escape = require(" + loaderUtils.stringifyRequest(this, require.resolve("./url/escape.js")) + ");\n";
92
+
86
93
  cssAsString = cssAsString.replace(result.urlItemRegExpG, function(item) {
87
94
  var match = result.urlItemRegExp.exec(item);
88
95
  var idx = +match[1];
@@ -94,22 +101,21 @@ module.exports = function(content, map) {
94
101
  if(idx > 0) { // idx === 0 is catched by isUrlRequest
95
102
  // in cases like url('webfont.eot?#iefix')
96
103
  urlRequest = url.substr(0, idx);
97
- return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"" +
104
+ return "\" + escape(require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")) + \"" +
98
105
  url.substr(idx);
99
106
  }
100
107
  urlRequest = url;
101
- return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
108
+ return "\" + escape(require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")) + \"";
102
109
  }.bind(this));
103
110
  }
104
-
105
-
111
+
106
112
  var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
107
113
  if (exportJs) {
108
114
  exportJs = "exports.locals = " + exportJs + ";";
109
115
  }
110
116
 
111
117
  var moduleJs;
112
- if(query.sourceMap && result.map) {
118
+ if(sourceMap && result.map) {
113
119
  // add a SourceMap
114
120
  map = result.map;
115
121
  if(map.sources) {
@@ -126,9 +132,10 @@ module.exports = function(content, map) {
126
132
  }
127
133
 
128
134
  // embed runtime
129
- callback(null, "exports = module.exports = require(" +
135
+ callback(null, urlEscapeHelper +
136
+ "exports = module.exports = require(" +
130
137
  loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) +
131
- ")(" + query.sourceMap + ");\n" +
138
+ ")(" + sourceMap + ");\n" +
132
139
  "// imports\n" +
133
140
  importJs + "\n\n" +
134
141
  "// module\n" +
@@ -6,6 +6,7 @@ var loaderUtils = require("loader-utils");
6
6
  var processCss = require("./processCss");
7
7
  var getImportPrefix = require("./getImportPrefix");
8
8
  var compileExports = require("./compile-exports");
9
+ var createResolver = require("./createResolver");
9
10
 
10
11
 
11
12
  module.exports = function(content) {
@@ -14,12 +15,14 @@ module.exports = function(content) {
14
15
  var query = loaderUtils.getOptions(this) || {};
15
16
  var moduleMode = query.modules || query.module;
16
17
  var camelCaseKeys = query.camelCase || query.camelcase;
18
+ var resolve = createResolver(query.alias);
17
19
 
18
20
  processCss(content, null, {
19
21
  mode: moduleMode ? "local" : "global",
20
22
  query: query,
21
23
  minimize: this.minimize,
22
- loaderContext: this
24
+ loaderContext: this,
25
+ resolve: resolve
23
26
  }, function(err, result) {
24
27
  if(err) return callback(err);
25
28
 
package/lib/processCss.js CHANGED
@@ -42,12 +42,12 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
42
42
  }
43
43
 
44
44
  if(options.import) {
45
- css.walkAtRules(/import/i, function(rule) {
45
+ css.walkAtRules(/^import$/i, function(rule) {
46
46
  var values = Tokenizer.parseValues(rule.params);
47
47
  var url = values.nodes[0].nodes[0];
48
- if(url.type === "url") {
48
+ if(url && url.type === "url") {
49
49
  url = url.url;
50
- } else if(url.type === "string") {
50
+ } else if(url && url.type === "string") {
51
51
  url = url.value;
52
52
  } else throw rule.error("Unexpected format " + rule.params);
53
53
  if (!url.replace(/\s/g, '').length) {
@@ -83,6 +83,11 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
83
83
  exports[exportName] = replaceImportsInString(exports[exportName]);
84
84
  });
85
85
 
86
+ function isAlias(url) {
87
+ // Handle alias starting by / and root disabled
88
+ return url !== options.resolve(url)
89
+ }
90
+
86
91
  function processNode(item) {
87
92
  switch (item.type) {
88
93
  case "value":
@@ -98,11 +103,9 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
98
103
  }
99
104
  break;
100
105
  case "url":
101
- if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
102
- // Don't remove quotes around url when contain space
103
- if (item.url.indexOf(" ") === -1) {
104
- item.stringType = "";
105
- }
106
+ if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || loaderUtils.isUrlRequest(item.url, options.root))) {
107
+ // Strip quotes, they will be re-added if the module needs them
108
+ item.stringType = "";
106
109
  delete item.innerSpacingBefore;
107
110
  delete item.innerSpacingAfter;
108
111
  var url = item.url;
@@ -149,7 +152,8 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
149
152
  root: root,
150
153
  mode: options.mode,
151
154
  url: query.url !== false,
152
- import: query.import !== false
155
+ import: query.import !== false,
156
+ resolve: options.resolve
153
157
  };
154
158
 
155
159
  var pipeline = postcss([
@@ -0,0 +1,13 @@
1
+ module.exports = function escape(url) {
2
+ // If url is already wrapped in quotes, remove them
3
+ if (/^['"].*['"]$/.test(url)) {
4
+ url = url.slice(1, -1);
5
+ }
6
+ // Should url be wrapped?
7
+ // See https://drafts.csswg.org/css-values-3/#urls
8
+ if (/["'() \t\n]/.test(url)) {
9
+ return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
10
+ }
11
+
12
+ return url
13
+ }
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "0.28.4",
3
+ "version": "0.28.8",
4
4
  "author": "Tobias Koppers @sokra",
5
+ "license": "MIT",
5
6
  "description": "css loader module for webpack",
6
7
  "engines": {
7
- "node": ">=0.12.0 || >=4.3.0 <5.0.0 || >=5.10"
8
+ "node": ">=0.12.0 || >= 4.3.0 < 5.0.0 || >=5.10"
8
9
  },
9
10
  "files": [
11
+ "lib",
10
12
  "index.js",
11
- "locals.js",
12
- "lib"
13
+ "locals.js"
13
14
  ],
14
15
  "dependencies": {
15
- "babel-code-frame": "^6.11.0",
16
+ "babel-code-frame": "^6.26.0",
16
17
  "css-selector-tokenizer": "^0.7.0",
17
- "cssnano": ">=2.6.1 <4",
18
+ "cssnano": "^3.10.0",
18
19
  "icss-utils": "^2.1.0",
19
20
  "loader-utils": "^1.0.2",
20
21
  "lodash.camelcase": "^4.3.0",
21
- "object-assign": "^4.0.1",
22
+ "object-assign": "^4.1.1",
22
23
  "postcss": "^5.0.6",
23
- "postcss-modules-extract-imports": "^1.0.0",
24
- "postcss-modules-local-by-default": "^1.0.1",
25
- "postcss-modules-scope": "^1.0.0",
26
- "postcss-modules-values": "^1.1.0",
24
+ "postcss-modules-extract-imports": "^1.1.0",
25
+ "postcss-modules-local-by-default": "^1.2.0",
26
+ "postcss-modules-scope": "^1.1.0",
27
+ "postcss-modules-values": "^1.3.0",
27
28
  "postcss-value-parser": "^3.3.0",
28
- "source-list-map": "^0.1.7"
29
+ "source-list-map": "^2.0.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "codecov": "^1.0.1",
@@ -36,17 +37,15 @@
36
37
  "standard-version": "^4.0.0"
37
38
  },
38
39
  "scripts": {
40
+ "lint": "eslint lib test",
39
41
  "test": "mocha",
42
+ "cover": "istanbul cover node_modules/mocha/bin/_mocha",
40
43
  "test:cover": "npm run cover -- --report lcovonly",
41
- "lint": "eslint lib test",
42
44
  "travis:test": "npm run cover",
43
45
  "travis:lint": "npm run lint",
44
- "cover": "istanbul cover node_modules/mocha/bin/_mocha",
45
- "release": "yarn run standard-version"
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "git@github.com:webpack/css-loader.git"
46
+ "release": "standard-version"
50
47
  },
51
- "license": "MIT"
48
+ "homepage": "https://github.com/webpack-contrib/css-loader",
49
+ "repository": "https://github.com/webpack-contrib/css-loader.git",
50
+ "bugs": "https://github.com/webpack-contrib/css-loader/issues"
52
51
  }