Skip to content

Commit 30192e6

Browse files
docs: updated
1 parent 2b74dbc commit 30192e6

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Use multi-process parallel running to improve the build speed.
146146
Default number of concurrent runs: `os.cpus().length - 1`.
147147

148148
> ℹ️ Parallelization can speedup your build significantly and is therefore **highly recommended**.
149+
> If a parallelization is enabled, the packages in `minimizerOptions` must be required via strings (`packageName` or `require.resolve(packageName)`). Read more in [`minimizerOptions`](#minimizerOptions)
149150
150151
#### `Boolean`
151152

@@ -297,6 +298,23 @@ module.exports = {
297298
The function index in the `minify` array corresponds to the options object with the same index in the `minimizerOptions` array.
298299
If you use `minimizerOptions` like object, all `minify` function accept it.
299300

301+
> If a parallelization is enabled, the packages in `minimizerOptions` must be required via strings (`packageName` or `require.resolve(packageName)`). In this case, we shouldn't use `require`/`import`.
302+
303+
```js
304+
module.exports = {
305+
optimization: {
306+
minimize: true,
307+
minimizer: [
308+
new CssMinimizerPlugin({
309+
minimizerOptions: {
310+
preset: require.resolve('cssnano-preset-simple'),
311+
},
312+
}),
313+
],
314+
},
315+
};
316+
```
317+
300318
#### `processorOptions`
301319

302320
Type: `Object`

package-lock.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"copy-webpack-plugin": "^8.1.1",
7070
"cross-env": "^7.0.2",
7171
"css-loader": "^5.2.1",
72+
"cssnano-preset-simple": "^2.0.0",
7273
"csso": "^4.0.3",
7374
"del": "^6.0.0",
7475
"del-cli": "^3.0.1",

test/__snapshots__/minimizerOptions-option.test.js.snap

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ exports[`when applied with "minimizerOptions" option matches snapshot for "parse
2525

2626
exports[`when applied with "minimizerOptions" option matches snapshot for "parser" option with "String" value: index.sss 1`] = `"a{color:#000}"`;
2727

28+
exports[`when applied with "minimizerOptions" option matches snapshot for "preset" option with require.resolve "String" value: default-preset 1`] = `"p{border:0 solid var(--test);border-radius:var(--test);border-width:1px}"`;
29+
30+
exports[`when applied with "minimizerOptions" option matches snapshot for "preset" option with require.resolve "String" value: preset-simple 1`] = `"p{border-width:1px;border-radius:var(--test);border:0 solid var(--test)}"`;
31+
2832
exports[`when applied with "minimizerOptions" option matches snapshot for "stringifier" option with "Function" value: entry.css 1`] = `"body color:reda color:#00f"`;
2933

3034
exports[`when applied with "minimizerOptions" option matches snapshot for "stringifier" option with "String" value: entry.css 1`] = `"body color:reda color:#00f"`;
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
p {
2+
border: 1px solid var(--test);
3+
border-radius: var(--test);
4+
border-width: 0;
5+
}

test/minimizerOptions-option.test.js

+52
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,58 @@ describe('when applied with "minimizerOptions" option', () => {
7575
});
7676
});
7777

78+
it('matches snapshot for "preset" option with require.resolve "String" value', () => {
79+
const compiler = getCompiler({
80+
entry: {
81+
entry: `${__dirname}/fixtures/minimizerOptions/order.css`,
82+
},
83+
});
84+
new CssMinimizerPlugin({
85+
minimizerOptions: {
86+
preset: 'default',
87+
},
88+
}).apply(compiler);
89+
90+
const compiler2 = getCompiler({
91+
entry: {
92+
entry: `${__dirname}/fixtures/minimizerOptions/order.css`,
93+
},
94+
});
95+
new CssMinimizerPlugin({
96+
minimizerOptions: {
97+
preset: require.resolve('cssnano-preset-simple'),
98+
},
99+
}).apply(compiler2);
100+
101+
const result1 = compile(compiler).then((stats) => {
102+
expect(stats.compilation.errors).toEqual([]);
103+
expect(stats.compilation.warnings).toEqual([]);
104+
105+
for (const file in stats.compilation.assets) {
106+
// eslint-disable-next-line no-continue
107+
if (/\.js$/.test(file)) continue;
108+
expect(readAsset(file, compiler, stats)).toMatchSnapshot(
109+
`default-preset`
110+
);
111+
}
112+
});
113+
114+
const result2 = compile(compiler2).then((stats) => {
115+
expect(stats.compilation.errors).toEqual([]);
116+
expect(stats.compilation.warnings).toEqual([]);
117+
118+
for (const file in stats.compilation.assets) {
119+
// eslint-disable-next-line no-continue
120+
if (/\.js$/.test(file)) continue;
121+
expect(readAsset(file, compiler2, stats)).toMatchSnapshot(
122+
`preset-simple`
123+
);
124+
}
125+
});
126+
127+
return Promise.all([result1, result2]);
128+
});
129+
78130
it('matches snapshot for "mergeRules" option (enable [default])', () => {
79131
const compiler = getCompiler({
80132
entry: {

0 commit comments

Comments
 (0)