css-loader 0.28.5 → 0.28.9
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 +41 -0
- package/README.md +11 -11
- package/lib/loader.js +15 -8
- package/lib/localsLoader.js +4 -1
- package/lib/processCss.js +10 -6
- package/lib/url/escape.js +16 -0
- package/package.json +18 -19
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
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.9"></a>
|
|
6
|
+
## [0.28.9](https://github.com/webpack-contrib/css-loader/compare/v0.28.8...v0.28.9) (2018-01-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* ignore invalid URLs (`url()`) ([#663](https://github.com/webpack-contrib/css-loader/issues/663)) ([d1d8221](https://github.com/webpack-contrib/css-loader/commit/d1d8221))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<a name="0.28.8"></a>
|
|
16
|
+
## [0.28.8](https://github.com/webpack-contrib/css-loader/compare/v0.28.7...v0.28.8) (2018-01-05)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **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))
|
|
22
|
+
* 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))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
<a name="0.28.7"></a>
|
|
27
|
+
## [0.28.7](https://github.com/webpack/css-loader/compare/v0.28.6...v0.28.7) (2017-08-30)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* pass resolver to `localsLoader` (`options.alias`) ([#601](https://github.com/webpack/css-loader/issues/601)) ([8f1b57c](https://github.com/webpack/css-loader/commit/8f1b57c))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<a name="0.28.6"></a>
|
|
37
|
+
## [0.28.6](https://github.com/webpack/css-loader/compare/v0.28.5...v0.28.6) (2017-08-30)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
* 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))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
5
46
|
<a name="0.28.5"></a>
|
|
6
47
|
## [0.28.5](https://github.com/webpack/css-loader/compare/v0.28.4...v0.28.5) (2017-08-17)
|
|
7
48
|
|
package/README.md
CHANGED
|
@@ -94,15 +94,15 @@ 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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
106
|
|**`localIdentName`**|`{String}`|`[hash:base64]`|Configure the generated ident|
|
|
107
107
|
|
|
108
108
|
### `root`
|
|
@@ -141,7 +141,7 @@ url(~module/image.png) => require('module/image.png')
|
|
|
141
141
|
|
|
142
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.).
|
|
143
143
|
|
|
144
|
-
`css-loader`'s `alias` follows the same syntax as webpack's `resolve.alias`, you can see the details at the [resolve docs]
|
|
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)
|
|
145
145
|
|
|
146
146
|
**file.scss**
|
|
147
147
|
```css
|
|
@@ -419,7 +419,7 @@ The query parameter `importLoaders` allows to configure how many loaders before
|
|
|
419
419
|
{
|
|
420
420
|
loader: 'css-loader',
|
|
421
421
|
options: {
|
|
422
|
-
importLoaders:
|
|
422
|
+
importLoaders: 2 // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
|
|
423
423
|
}
|
|
424
424
|
},
|
|
425
425
|
'postcss-loader',
|
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
|
-
|
|
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(
|
|
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,
|
|
135
|
+
callback(null, urlEscapeHelper +
|
|
136
|
+
"exports = module.exports = require(" +
|
|
130
137
|
loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) +
|
|
131
|
-
")(" +
|
|
138
|
+
")(" + sourceMap + ");\n" +
|
|
132
139
|
"// imports\n" +
|
|
133
140
|
importJs + "\n\n" +
|
|
134
141
|
"// module\n" +
|
package/lib/localsLoader.js
CHANGED
|
@@ -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
|
@@ -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
|
-
//
|
|
103
|
-
|
|
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,16 @@
|
|
|
1
|
+
module.exports = function escape(url) {
|
|
2
|
+
if (typeof url !== 'string') {
|
|
3
|
+
return url
|
|
4
|
+
}
|
|
5
|
+
// If url is already wrapped in quotes, remove them
|
|
6
|
+
if (/^['"].*['"]$/.test(url)) {
|
|
7
|
+
url = url.slice(1, -1);
|
|
8
|
+
}
|
|
9
|
+
// Should url be wrapped?
|
|
10
|
+
// See https://drafts.csswg.org/css-values-3/#urls
|
|
11
|
+
if (/["'() \t\n]/.test(url)) {
|
|
12
|
+
return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return url
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.9",
|
|
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.
|
|
16
|
+
"babel-code-frame": "^6.26.0",
|
|
16
17
|
"css-selector-tokenizer": "^0.7.0",
|
|
17
|
-
"cssnano": "
|
|
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.
|
|
22
|
+
"object-assign": "^4.1.1",
|
|
22
23
|
"postcss": "^5.0.6",
|
|
23
|
-
"postcss-modules-extract-imports": "^1.
|
|
24
|
-
"postcss-modules-local-by-default": "^1.0
|
|
25
|
-
"postcss-modules-scope": "^1.
|
|
26
|
-
"postcss-modules-values": "^1.
|
|
24
|
+
"postcss-modules-extract-imports": "^1.2.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
29
|
"source-list-map": "^2.0.0"
|
|
29
30
|
},
|
|
@@ -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
|
-
"
|
|
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
|
-
"
|
|
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
|
}
|