@@ -117,7 +117,7 @@ module.exports = {
117
117
| Name | Type | Default | Description |
118
118
| :-----------------------------------------: | :-------------------: | :-------------: | :------------------------------------------ |
119
119
| ** [ ` url ` ] ( #url ) ** | ` {Boolean\|Function} ` | ` true ` | Enable/Disable ` url() ` handling |
120
- | ** [ ` import ` ] ( #import ) ** | ` {Boolean} ` | ` true ` | Enable/Disable @import handling |
120
+ | ** [ ` import ` ] ( #import ) ** | ` {Boolean\/Function} ` | ` true ` | Enable/Disable @import handling |
121
121
| ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
122
122
| ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
123
123
| ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
@@ -130,19 +130,24 @@ module.exports = {
130
130
Type: ` Boolean|Function `
131
131
Default: ` true `
132
132
133
- Control ` url() ` resolving. Absolute ` urls ` are not resolving by default .
133
+ Control ` url() ` resolving. Absolute urls are not resolving.
134
134
135
135
Examples resolutions:
136
136
137
137
```
138
138
url(image.png) => require('./image.png')
139
+ url('image.png') => require('./image.png')
139
140
url(./image.png) => require('./image.png')
141
+ url('./image.png') => require('./image.png')
142
+ url('http://dontwritehorriblecode.com/2112.png') => require('http://dontwritehorriblecode.com/2112.png')
143
+ image-set(url('image2x.png') 1x, url('image1x.png') 2x) => require('./image1x.png') and require('./image2x.png')
140
144
```
141
145
142
146
To import assets from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
143
147
144
148
```
145
149
url(~module/image.png) => require('module/image.png')
150
+ url('~module/image.png') => require('module/image.png')
146
151
url(~aliasDirectory/image.png) => require('otherDirectory/image.png')
147
152
```
148
153
@@ -170,7 +175,9 @@ module.exports = {
170
175
171
176
#### ` Function `
172
177
173
- Allow to filter ` url() ` . All filtered ` url() ` will not be resolved.
178
+ Allow to filter ` url() ` . All filtered ` url() ` will not be resolved (left in the code as they were written).
179
+
180
+ ** webpack.config.js**
174
181
175
182
``` js
176
183
module .exports = {
@@ -181,6 +188,8 @@ module.exports = {
181
188
loader: ' css-loader' ,
182
189
options: {
183
190
url : (url , resourcePath ) => {
191
+ // resourcePath - path to css file
192
+
184
193
// `url()` with `img.png` stay untouched
185
194
return url .includes (' img.png' );
186
195
},
@@ -196,7 +205,31 @@ module.exports = {
196
205
Type: ` Boolean `
197
206
Default: ` true `
198
207
199
- Enable/disable ` @import ` resolving. Absolute urls are not resolving.
208
+ Control ` @import ` resolving. Absolute urls in ` @import ` will be moved in runtime code.
209
+
210
+ Examples resolutions:
211
+
212
+ ```
213
+ @import 'style.css' => require('./style.css')
214
+ @import url(style.css) => require('./style.css')
215
+ @import url('style.css') => require('./style.css')
216
+ @import './style.css' => require('./style.css')
217
+ @import url(./style.css) => require('./style.css')
218
+ @import url('./style.css') => require('./style.css')
219
+ @import url('http://dontwritehorriblecode.com/style.css') => @import url('http://dontwritehorriblecode.com/style.css') in runtime
220
+ ```
221
+
222
+ To import styles from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
223
+
224
+ ```
225
+ @import url(~module/style.css) => require('module/style.css')
226
+ @import url('~module/style.css') => require('module/style.css')
227
+ @import url(~aliasDirectory/style.css) => require('otherDirectory/style.css')
228
+ ```
229
+
230
+ #### ` Boolean `
231
+
232
+ Enable/disable ` @import ` resolving.
200
233
201
234
** webpack.config.js**
202
235
@@ -216,22 +249,33 @@ module.exports = {
216
249
};
217
250
```
218
251
219
- Examples resolutions:
252
+ #### ` Function `
220
253
221
- ```
222
- @import 'style.css' => require('./style.css')
223
- @import url(style.css) => require('./style.css')
224
- @import url('style.css') => require('./style.css')
225
- @import './style.css' => require('./style.css')
226
- @import url(./style.css) => require('./style.css')
227
- @import url('./style.css') => require('./style.css')
228
- ```
254
+ Allow to filter ` @import ` . All filtered ` @import ` will not be resolved (left in the code as they were written).
229
255
230
- To import styles from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
256
+ ** webpack.config.js **
231
257
232
- ```
233
- @import url(~module/style.css) => require('module/style.css')
234
- @import url(~aliasDirectory/style.css) => require('otherDirectory/style.css')
258
+ ``` js
259
+ module .exports = {
260
+ module: {
261
+ rules: [
262
+ {
263
+ test: / \. css$ / ,
264
+ loader: ' css-loader' ,
265
+ options: {
266
+ import : (parsedImport , resourcePath ) => {
267
+ // parsedImport.url - url of `@import`
268
+ // parsedImport.media - media query of `@import`
269
+ // resourcePath - path to css file
270
+
271
+ // `@import` with `style.css` stay untouched
272
+ return parsedImport .url .includes (' style.css' );
273
+ },
274
+ },
275
+ },
276
+ ],
277
+ },
278
+ };
235
279
```
236
280
237
281
### [ ` modules ` ] ( https://github.com/css-modules/css-modules )
0 commit comments