Skip to content

Commit e7c5837

Browse files
refactor: config autoload (#440)
feat: the `config` option can be `string` or `boolean`, you can specify absolute path to the config
1 parent e3f8ee4 commit e7c5837

40 files changed

+2438
-757
lines changed

README.md

+60-11
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ module.exports = {
111111

112112
<h2 align="center">Options</h2>
113113

114-
| Name | Type | Default | Description |
115-
| :------------------------: | :-----------------: | :---------: | :------------------------------------------- |
116-
| [`exec`](#exec) | `{Boolean}` | `undefined` | Enable PostCSS Parser support in `CSS-in-JS` |
117-
| [`parser`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Parser |
118-
| [`syntax`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Syntax |
119-
| [`stringifier`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Stringifier |
120-
| [`config`](#config) | `{Object}` | `undefined` | Set `postcss.config.js` config path && `ctx` |
121-
| [`plugins`](#plugins) | `{Array\|Function}` | `[]` | Set PostCSS Plugins |
122-
| [`sourceMap`](#sourcemap) | `{String\|Boolean}` | `false` | Enable Source Maps |
114+
| Name | Type | Default | Description |
115+
| :------------------------: | :-------------------------: | :---------: | :------------------------------------------- |
116+
| [`exec`](#exec) | `{Boolean}` | `undefined` | Enable PostCSS Parser support in `CSS-in-JS` |
117+
| [`parser`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Parser |
118+
| [`syntax`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Syntax |
119+
| [`stringifier`](#syntaxes) | `{String\|Object}` | `undefined` | Set PostCSS Stringifier |
120+
| [`config`](#config) | `{String\|Object\|Boolean}` | `undefined` | Set `postcss.config.js` config path && `ctx` |
121+
| [`plugins`](#plugins) | `{Array\|Function}` | `[]` | Set PostCSS Plugins |
122+
| [`sourceMap`](#sourcemap) | `{String\|Boolean}` | `false` | Enable Source Maps |
123123

124124
### `Exec`
125125

@@ -140,12 +140,61 @@ If you use JS styles without the [`postcss-js`][postcss-js] parser, add the `exe
140140

141141
### `Config`
142142

143+
Type: `Boolean|String|Object`
144+
Default: `undefined`
145+
146+
#### Boolean
147+
148+
Enables/Disables autoloading config.
149+
150+
**webpack.config.js**
151+
152+
```js
153+
module.exports = {
154+
module: {
155+
rules: [
156+
{
157+
test: /\.css$/i,
158+
loader: 'postcss-loader',
159+
options: {
160+
config: false,
161+
},
162+
},
163+
],
164+
},
165+
};
166+
```
167+
168+
#### String
169+
170+
Allows to specify the absolute path to the config file.
171+
172+
**webpack.config.js**
173+
174+
```js
175+
module.exports = {
176+
module: {
177+
rules: [
178+
{
179+
test: /\.css$/i,
180+
loader: 'postcss-loader',
181+
options: {
182+
config: path.resolve(__dirname, 'custom.config.js'),
183+
},
184+
},
185+
],
186+
},
187+
};
188+
```
189+
190+
#### Object
191+
143192
| Name | Type | Default | Description |
144193
| :-----------------------: | :--------: | :---------: | :----------------------- |
145194
| [`path`](#path) | `{String}` | `undefined` | PostCSS Config Directory |
146195
| [`context`](#context-ctx) | `{Object}` | `undefined` | PostCSS Config Context |
147196

148-
#### `Path`
197+
##### `Path`
149198

150199
You can manually specify the path to search for your config (`postcss.config.js`) with the `config.path` option. This is needed if you store your config in a separate e.g `./config || ./.config` folder.
151200

@@ -169,7 +218,7 @@ You can manually specify the path to search for your config (`postcss.config.js`
169218

170219
[supported config formats]: https://github.com/michael-ciniawsky/postcss-load-config#usage
171220

172-
#### `Context (ctx)`
221+
##### `Context (ctx)`
173222

174223
| Name | Type | Default | Description |
175224
| :-------: | :--------: | :-------------------: | :------------------------------- |

0 commit comments

Comments
 (0)