Skip to content

Commit a043922

Browse files
feat: parser and stringifier options can be Function
1 parent f667a7b commit a043922

File tree

10 files changed

+512
-28
lines changed

10 files changed

+512
-28
lines changed

README.md

Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ module.exports = {
114114
| Name | Type | Default | Description |
115115
| :------------------------: | :-------------------------------------------: | :----------------: | :------------------------------------------- |
116116
| [`exec`](#exec) | `{Boolean}` | `undefined` | Enable PostCSS Parser support in `CSS-in-JS` |
117-
| [`parser`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Parser |
117+
| [`parser`](#syntaxes) | `{String\|Object\|Function}` | `undefined` | Set PostCSS Parser |
118118
| [`syntax`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Syntax |
119-
| [`stringifier`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Stringifier |
119+
| [`stringifier`](#syntaxes) | `{String\|Object\|Function}` | `undefined` | Set PostCSS Stringifier |
120120
| [`config`](#config) | `{String\|Object\|Boolean}` | `undefined` | Set `postcss.config.js` config path && `ctx` |
121121
| [`plugins`](#plugins) | `{Function\|Object\|Array<Function\|Object>}` | `[]` | Set PostCSS Plugins |
122122
| [`sourceMap`](#sourcemap) | `{String\|Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
@@ -390,17 +390,21 @@ module.exports = {
390390
Type: `String|Object`
391391
Default: `undefined`
392392

393-
| Name | Type | Default | Description |
394-
| :---------------------------: | :----------------: | :---------: | :------------------------- |
395-
| [`parser`](#parser) | `{String\|Object}` | `undefined` | Custom PostCSS Parser |
396-
| [`syntax`](#syntax) | `{String\|Object}` | `undefined` | Custom PostCSS Syntax |
397-
| [`stringifier`](#stringifier) | `{String\|Object}` | `undefined` | Custom PostCSS Stringifier |
393+
| Name | Type | Default | Description |
394+
| :---------------------------: | :--------------------------: | :---------: | :------------------------- |
395+
| [`parser`](#parser) | `{String\|Object}` | `undefined` | Custom PostCSS Parser |
396+
| [`syntax`](#syntax) | `{String\|Object}` | `undefined` | Custom PostCSS Syntax |
397+
| [`stringifier`](#stringifier) | `{String\|Object\|Function}` | `undefined` | Custom PostCSS Stringifier |
398398

399399
#### `Parser`
400400

401-
Type: `String|Object`
401+
Type: `String|Object|Function`
402402
Default: `undefined`
403403

404+
##### `String`
405+
406+
The passed `string` is converted to the form `require('string')`.
407+
404408
**`webpack.config.js`**
405409

406410
```js
@@ -411,6 +415,7 @@ module.exports = {
411415
test: /\.sss$/i,
412416
loader: 'postcss-loader',
413417
options: {
418+
// Will be converted to `require('sugarss')`
414419
parser: 'sugarss',
415420
},
416421
},
@@ -419,11 +424,55 @@ module.exports = {
419424
};
420425
```
421426

427+
##### `Object`
428+
429+
**`webpack.config.js`**
430+
431+
```js
432+
module.exports = {
433+
module: {
434+
rules: [
435+
{
436+
test: /\.sss$/i,
437+
loader: 'postcss-loader',
438+
options: {
439+
parser: require('sugarss'),
440+
},
441+
},
442+
],
443+
},
444+
};
445+
```
446+
447+
##### `Function`
448+
449+
**`webpack.config.js`**
450+
451+
```js
452+
module.exports = {
453+
module: {
454+
rules: [
455+
{
456+
test: /\.sss$/i,
457+
loader: 'postcss-loader',
458+
options: {
459+
parser: require('sugarss').parse,
460+
},
461+
},
462+
],
463+
},
464+
};
465+
```
466+
422467
#### `Syntax`
423468

424469
Type: `String|Object`
425470
Default: `undefined`
426471

472+
##### `String`
473+
474+
The passed `string` is converted to the form `require('string')`.
475+
427476
**`webpack.config.js`**
428477

429478
```js
@@ -434,6 +483,7 @@ module.exports = {
434483
test: /\.css$/i,
435484
loader: 'postcss-loader',
436485
options: {
486+
// Will be converted to `require('sugarss')`
437487
syntax: 'sugarss',
438488
},
439489
},
@@ -442,11 +492,35 @@ module.exports = {
442492
};
443493
```
444494

495+
##### `Object`
496+
497+
**`webpack.config.js`**
498+
499+
```js
500+
module.exports = {
501+
module: {
502+
rules: [
503+
{
504+
test: /\.css$/i,
505+
loader: 'postcss-loader',
506+
options: {
507+
stringifier: require('sugarss'),
508+
},
509+
},
510+
],
511+
},
512+
};
513+
```
514+
445515
#### `Stringifier`
446516

447-
Type: `String|Object`
517+
Type: `String|Object|Function`
448518
Default: `undefined`
449519

520+
##### `String`
521+
522+
The passed `string` is converted to the form `require('string')`.
523+
450524
**`webpack.config.js`**
451525

452526
```js
@@ -457,7 +531,51 @@ module.exports = {
457531
test: /\.css$/i,
458532
loader: 'postcss-loader',
459533
options: {
460-
stringifier: 'midas',
534+
// Will be converted to `require('sugarss')`
535+
stringifier: 'sugarss',
536+
},
537+
},
538+
],
539+
},
540+
};
541+
```
542+
543+
##### `Object`
544+
545+
**`webpack.config.js`**
546+
547+
```js
548+
module.exports = {
549+
module: {
550+
rules: [
551+
{
552+
test: /\.css$/i,
553+
loader: 'postcss-loader',
554+
options: {
555+
stringifier: require('sugarss'),
556+
},
557+
},
558+
],
559+
},
560+
};
561+
```
562+
563+
##### `Function`
564+
565+
**`webpack.config.js`**
566+
567+
```js
568+
const Midas = require('midas');
569+
const midas = new Midas();
570+
571+
module.exports = {
572+
module: {
573+
rules: [
574+
{
575+
test: /\.css$/i,
576+
loader: 'postcss-loader',
577+
options: {
578+
stringifier: midas.stringifier,
461579
},
462580
},
463581
],

0 commit comments

Comments
 (0)