css-loader 0.27.3 → 0.28.0
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 +10 -0
- package/README.md +42 -3
- package/lib/createResolver.js +36 -0
- package/lib/loader.js +3 -1
- package/lib/processCss.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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.0"></a>
|
|
6
|
+
# [0.28.0](https://github.com/webpack/css-loader/compare/v0.27.3...v0.28.0) (2017-03-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add alias feature to rewrite URLs ([#274](https://github.com/webpack/css-loader/issues/274)) ([c8db489](https://github.com/webpack/css-loader/commit/c8db489))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
<a name="0.27.3"></a>
|
|
6
16
|
## [0.27.3](https://github.com/webpack/css-loader/compare/v0.27.2...v0.27.3) (2017-03-13)
|
|
7
17
|
|
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ To be compatible with existing css files (if not in CSS Module mode):
|
|
|
89
89
|
|**`sourceMap`**|`false`|Enable/Disable Sourcemaps|
|
|
90
90
|
|**`camelCase`**|`false`|Export Classnames in CamelCase|
|
|
91
91
|
|**`importLoaders`**|`0`|Number of loaders applied before CSS loader|
|
|
92
|
+
|**`alias`**|`{}`|Create aliases to import certain modules more easily|
|
|
92
93
|
|
|
93
94
|
The following webpack config can load CSS files, embed small PNG/JPG/GIF/SVG images as well as fonts as [Data URLs](https://tools.ietf.org/html/rfc2397) and copy larger files to the output directory.
|
|
94
95
|
|
|
@@ -322,7 +323,7 @@ They are not enabled by default because they expose a runtime overhead and incre
|
|
|
322
323
|
|
|
323
324
|
### toString
|
|
324
325
|
|
|
325
|
-
You can also use the css-loader results directly as string, such as in Angular's component style.
|
|
326
|
+
You can also use the css-loader results directly as string, such as in Angular's component style.
|
|
326
327
|
|
|
327
328
|
**webpack.config.js**
|
|
328
329
|
|
|
@@ -404,8 +405,8 @@ By default, the exported JSON keys mirror the class names. If you want to cameli
|
|
|
404
405
|
|:----:|:--------|
|
|
405
406
|
|**`true`**|Class names will be camelized|
|
|
406
407
|
|**`'dashes'`**|Only dashes in class names will be camelized|
|
|
407
|
-
|**`'only'`** |Class names will be camelized, the original class name will be removed from the locals|
|
|
408
|
-
|**`'dashesOnly'`**|Dashes in class names will be camelized, the original class name will be removed from the locals|
|
|
408
|
+
|**`'only'`** |Introduced in `0.27.1`. Class names will be camelized, the original class name will be removed from the locals|
|
|
409
|
+
|**`'dashesOnly'`**|Introduced in `0.27.1`. Dashes in class names will be camelized, the original class name will be removed from the locals|
|
|
409
410
|
|
|
410
411
|
**webpack.config.js**
|
|
411
412
|
```js
|
|
@@ -430,6 +431,44 @@ By default, the exported JSON keys mirror the class names. If you want to cameli
|
|
|
430
431
|
import { className } from 'file.css';
|
|
431
432
|
```
|
|
432
433
|
|
|
434
|
+
### Alias
|
|
435
|
+
|
|
436
|
+
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.).
|
|
437
|
+
|
|
438
|
+
#### Possible Options
|
|
439
|
+
|
|
440
|
+
css-loader's `alias` follows the same syntax as webpack's `resolve.alias`, you can see the details at: https://webpack.js.org/configuration/resolve/#resolve-alias
|
|
441
|
+
|
|
442
|
+
**webpack.config.js**
|
|
443
|
+
```js
|
|
444
|
+
{
|
|
445
|
+
test: /\.scss$/,
|
|
446
|
+
use: [{
|
|
447
|
+
loader: "style-loader"
|
|
448
|
+
}, {
|
|
449
|
+
loader: "css-loader",
|
|
450
|
+
options: {
|
|
451
|
+
alias: {
|
|
452
|
+
"../fonts/bootstrap": "bootstrap-sass/assets/fonts/bootstrap"
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
loader: "sass-loader",
|
|
457
|
+
options: {
|
|
458
|
+
includePaths: [
|
|
459
|
+
path.resolve("./node_modules/bootstrap-sass/assets/stylesheets")
|
|
460
|
+
]
|
|
461
|
+
}
|
|
462
|
+
}]
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
```scss
|
|
467
|
+
@charset "UTF-8";
|
|
468
|
+
@import "bootstrap";
|
|
469
|
+
```
|
|
470
|
+
Check out this [working bootstrap example](https://github.com/bbtfr/webpack2-bootstrap-sass-sample).
|
|
471
|
+
|
|
433
472
|
<h2 align="center">Maintainers</h2>
|
|
434
473
|
|
|
435
474
|
<table>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module.exports = function createResolver(alias) {
|
|
2
|
+
if(typeof alias !== "object" || Array.isArray(alias)) {
|
|
3
|
+
return function(url) {
|
|
4
|
+
return url
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
alias = Object.keys(alias).map(function(key) {
|
|
9
|
+
var onlyModule = false;
|
|
10
|
+
var obj = alias[key];
|
|
11
|
+
if(/\$$/.test(key)) {
|
|
12
|
+
onlyModule = true;
|
|
13
|
+
key = key.substr(0, key.length - 1);
|
|
14
|
+
}
|
|
15
|
+
if(typeof obj === "string") {
|
|
16
|
+
obj = {
|
|
17
|
+
alias: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
obj = Object.assign({
|
|
21
|
+
name: key,
|
|
22
|
+
onlyModule: onlyModule
|
|
23
|
+
}, obj);
|
|
24
|
+
return obj;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return function(url) {
|
|
28
|
+
alias.forEach(function(obj) {
|
|
29
|
+
var name = obj.name;
|
|
30
|
+
if(url === name || (!obj.onlyModule && url.startsWith(name + "/"))) {
|
|
31
|
+
url = obj.alias + url.substr(name.length);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/lib/loader.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, map) {
|
|
@@ -15,6 +16,7 @@ module.exports = function(content, map) {
|
|
|
15
16
|
var root = query.root;
|
|
16
17
|
var moduleMode = query.modules || query.module;
|
|
17
18
|
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
19
|
+
var resolve = createResolver(query.alias);
|
|
18
20
|
|
|
19
21
|
if(map !== null && typeof map !== "string") {
|
|
20
22
|
map = JSON.stringify(map);
|
|
@@ -69,7 +71,7 @@ module.exports = function(content, map) {
|
|
|
69
71
|
var match = result.urlItemRegExp.exec(item);
|
|
70
72
|
var idx = +match[1];
|
|
71
73
|
var urlItem = result.urlItems[idx];
|
|
72
|
-
var url = urlItem.url;
|
|
74
|
+
var url = resolve(urlItem.url);
|
|
73
75
|
idx = url.indexOf("?#");
|
|
74
76
|
if(idx < 0) idx = url.indexOf("#");
|
|
75
77
|
var urlRequest;
|
package/lib/processCss.js
CHANGED
|
@@ -13,7 +13,6 @@ var localByDefault = require("postcss-modules-local-by-default");
|
|
|
13
13
|
var extractImports = require("postcss-modules-extract-imports");
|
|
14
14
|
var modulesScope = require("postcss-modules-scope");
|
|
15
15
|
var modulesValues = require("postcss-modules-values");
|
|
16
|
-
var cssnano = require("cssnano");
|
|
17
16
|
|
|
18
17
|
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
19
18
|
return function(css) {
|
|
@@ -141,7 +140,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
141
140
|
var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
|
|
142
141
|
|
|
143
142
|
var customGetLocalIdent = query.getLocalIdent || getLocalIdent;
|
|
144
|
-
|
|
143
|
+
|
|
145
144
|
var parserOptions = {
|
|
146
145
|
root: root,
|
|
147
146
|
mode: options.mode,
|
|
@@ -179,6 +178,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
179
178
|
]);
|
|
180
179
|
|
|
181
180
|
if(minimize) {
|
|
181
|
+
var cssnano = require("cssnano");
|
|
182
182
|
var minimizeOptions = assign({}, query.minimize);
|
|
183
183
|
["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents", "autoprefixer"].forEach(function(name) {
|
|
184
184
|
if(typeof minimizeOptions[name] === "undefined")
|