Skip to content

Commit 7175174

Browse files
committed
allow to pass minimize options via query params
1 parent 5bf1893 commit 7175174

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ This may change in the future, when the module system (i. e. webpack) supports l
219219

220220
By default the css-loader minimizes the css if specified by the module system.
221221

222-
In some cases the minification is destructive to the css, so you can provide some options to it. clean-css is used for minification and you find a [list of options here](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-programmatically). Just provide them as query parameter: i. e. `require("css-loader?-restructuring&compatibility")` to disable restructuring and enable compatibility mode.
222+
In some cases the minification is destructive to the css, so you can provide some options to it. cssnano is used for minification and you find a [list of options here](http://cssnano.co/options/). Just provide them as query parameter: i. e. `require("css-loader?-autoprefixer")` to disable removing of deprecated vendor prefixes.
223223

224224
You can also disable or enforce minification with the `minimize` query parameter.
225225

lib/processCss.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ module.exports = function processCss(inputSource, inputMap, options) {
124124
var forceMinimize = query.minimize;
125125
var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
126126

127-
128127
var parserOptions = {
129128
root: root,
130129
mode: options.mode
@@ -159,12 +158,12 @@ module.exports = function processCss(inputSource, inputMap, options) {
159158
]);
160159

161160
if(minimize) {
162-
pipeline.use(cssnano({
163-
zindex: false,
164-
urls: false,
165-
unused: false,
166-
idents: false
167-
}));
161+
var minimizeOptions = Object.create(query);
162+
["zindex", "urls", "unused", "idents"].forEach(function(name) {
163+
if(typeof minimizeOptions[name] === "undefined")
164+
minimizeOptions[name] = false;
165+
});
166+
pipeline.use(cssnano(minimizeOptions));
168167
}
169168

170169
var result = pipeline.process(inputSource, {

test/moduleMinimizeTest.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*globals describe */
2+
3+
var test = require("./helpers").testSingleItem;
4+
5+
var path = require("path");
6+
var fs = require("fs");
7+
var testCasesPath = path.join(__dirname, "moduleMinimizeTestCases");
8+
var testCases = fs.readdirSync(testCasesPath);
9+
10+
describe("module", function() {
11+
testCases.forEach(function(name) {
12+
var source = fs.readFileSync(path.join(testCasesPath, name, "source.css"), "utf-8");
13+
var expected = fs.readFileSync(path.join(testCasesPath, name, "expected.css"), "utf-8");
14+
15+
test(name, source, expected, "?module&minimize&sourceMap&-comments&localIdentName=_[local]_");
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@keyframes _bounce_{0%{transform:translateY(-100%);opacity:0}5%{transform:translateY(-50%);opacity:1}}@keyframes _bounce2_{0%{transform:translateY(-100%);opacity:0}50%{transform:translateY(-50%);opacity:1}}
2+
3+
/* comment */._bounce_{animation-name:_bounce_;animation:_bounce2_ 1s ease;z-index:1442}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@keyframes bounce {
2+
0% {
3+
transform: translateY(-100%);
4+
opacity: 0;
5+
}
6+
5% {
7+
transform: translateY(-50%);
8+
opacity: 1;
9+
}
10+
}
11+
12+
@keyframes bounce2 {
13+
0% {
14+
transform: translateY(-100%);
15+
opacity: 0;
16+
}
17+
50% {
18+
transform: translateY(-50%);
19+
opacity: 1;
20+
}
21+
}
22+
23+
/* comment */
24+
.bounce {
25+
animation-name: bounce;
26+
animation: bounce2 1s ease;
27+
z-index: 1442;
28+
}

0 commit comments

Comments
 (0)