@@ -114,23 +114,41 @@ module.exports = {
114
114
115
115
## Options
116
116
117
- | Name | Type | Default | Description |
118
- | :-----------------------------------------: | :-----------------: | :-------------: | :------------------------------------------ |
119
- | ** [ ` url ` ] ( #url ) ** | ` {Boolean} ` | ` true ` | Enable/Disable ` url() ` handling |
120
- | ** [ ` import ` ] ( #import ) ** | ` {Boolean} ` | ` true ` | Enable/Disable @import handling |
121
- | ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
122
- | ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
123
- | ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
124
- | ** [ ` camelCase ` ] ( #camelcase ) ** | ` {Boolean\|String} ` | ` false ` | Export Classnames in CamelCase |
125
- | ** [ ` importLoaders ` ] ( #importloaders ) ** | ` {Number} ` | ` 0 ` | Number of loaders applied before CSS loader |
126
- | ** [ ` exportOnlyLocals ` ] ( #exportonlylocals ) ** | ` {Boolean} ` | ` false ` | Export only locals |
117
+ | Name | Type | Default | Description |
118
+ | :-----------------------------------------: | :------------------- : | :-------------: | :------------------------------------------ |
119
+ | ** [ ` url ` ] ( #url ) ** | ` {Boolean\|Function} ` | ` true ` | Enable/Disable ` url() ` handling |
120
+ | ** [ ` import ` ] ( #import ) ** | ` {Boolean} ` | ` true ` | Enable/Disable @import handling |
121
+ | ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
122
+ | ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
123
+ | ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
124
+ | ** [ ` camelCase ` ] ( #camelcase ) ** | ` {Boolean\|String} ` | ` false ` | Export Classnames in CamelCase |
125
+ | ** [ ` importLoaders ` ] ( #importloaders ) ** | ` {Number} ` | ` 0 ` | Number of loaders applied before CSS loader |
126
+ | ** [ ` exportOnlyLocals ` ] ( #exportonlylocals ) ** | ` {Boolean} ` | ` false ` | Export only locals |
127
127
128
128
### ` url `
129
129
130
- Type: ` Boolean `
130
+ Type: ` Boolean|Function `
131
131
Default: ` true `
132
132
133
- Enable/disable ` url() ` resolving. Absolute ` urls ` are not resolving by default.
133
+ Control ` url() ` resolving. Absolute ` urls ` are not resolving by default.
134
+
135
+ Examples resolutions:
136
+
137
+ ```
138
+ url(image.png) => require('./image.png')
139
+ url(./image.png) => require('./image.png')
140
+ ```
141
+
142
+ To import assets from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
143
+
144
+ ```
145
+ url(~module/image.png) => require('module/image.png')
146
+ url(~aliasDirectory/image.png) => require('otherDirectory/image.png')
147
+ ```
148
+
149
+ #### ` Boolean `
150
+
151
+ Enable/disable ` url() ` resolving.
134
152
135
153
** webpack.config.js**
136
154
@@ -150,18 +168,27 @@ module.exports = {
150
168
};
151
169
```
152
170
153
- Examples resolutions:
171
+ #### ` Function `
154
172
155
- ```
156
- url(image.png) => require('./image.png')
157
- url(./image.png) => require('./image.png')
158
- ```
159
-
160
- To import assets from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
173
+ Allow to filter ` url() ` . All filtered ` url() ` will not be resolved.
161
174
162
- ```
163
- url(~module/image.png) => require('module/image.png')
164
- url(~aliasDirectory/image.png) => require('otherDirectory/image.png')
175
+ ``` js
176
+ module .exports = {
177
+ module: {
178
+ rules: [
179
+ {
180
+ test: / \. css$ / ,
181
+ loader: ' css-loader' ,
182
+ options: {
183
+ url : (url , resourcePath ) => {
184
+ // `url()` with `img.png` stay untouched
185
+ return url .includes (' img.png' );
186
+ },
187
+ },
188
+ },
189
+ ],
190
+ },
191
+ };
165
192
```
166
193
167
194
### ` import `
0 commit comments