@@ -117,7 +117,7 @@ module.exports = {
117117| Name | Type | Default | Description |
118118| :-----------------------------------------: | :-------------------: | :-------------: | :------------------------------------------ |
119119| ** [ ` 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 |
121121| ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
122122| ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
123123| ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
@@ -130,19 +130,24 @@ module.exports = {
130130Type: ` Boolean|Function `
131131Default: ` true `
132132
133- Control ` url() ` resolving. Absolute ` urls ` are not resolving by default .
133+ Control ` url() ` resolving. Absolute urls are not resolving.
134134
135135Examples resolutions:
136136
137137```
138138url(image.png) => require('./image.png')
139+ url('image.png') => require('./image.png')
139140url(./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')
140144```
141145
142146To import assets from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
143147
144148```
145149url(~module/image.png) => require('module/image.png')
150+ url('~module/image.png') => require('module/image.png')
146151url(~aliasDirectory/image.png) => require('otherDirectory/image.png')
147152```
148153
@@ -170,7 +175,9 @@ module.exports = {
170175
171176#### ` Function `
172177
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**
174181
175182``` js
176183module .exports = {
@@ -181,6 +188,8 @@ module.exports = {
181188 loader: ' css-loader' ,
182189 options: {
183190 url : (url , resourcePath ) => {
191+ // resourcePath - path to css file
192+
184193 // `url()` with `img.png` stay untouched
185194 return url .includes (' img.png' );
186195 },
@@ -196,7 +205,31 @@ module.exports = {
196205Type: ` Boolean `
197206Default: ` true `
198207
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.
200233
201234** webpack.config.js**
202235
@@ -216,22 +249,33 @@ module.exports = {
216249};
217250```
218251
219- Examples resolutions:
252+ #### ` Function `
220253
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).
229255
230- To import styles from a ` node_modules ` path (include ` resolve.modules ` ) and for ` alias ` , prefix it with a ` ~ ` :
256+ ** webpack.config.js **
231257
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+ };
235279```
236280
237281### [ ` modules ` ] ( https://github.com/css-modules/css-modules )
0 commit comments