Skip to content

Commit e9eb5ad

Browse files
fix: invert Function behavior for url and import options (#939)
BREAKING CHANGE: you should return `true` when you want handle `url`/`@import` and return `false` if not
1 parent 888cca0 commit e9eb5ad

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,13 @@ module.exports = {
183183
options: {
184184
url: (url, resourcePath) => {
185185
// resourcePath - path to css file
186+
187+
// Don't handle `img.png` urls
188+
if (url.includes('img.png')) {
189+
return false;
190+
}
186191

187-
// `url()` with `img.png` stay untouched
188-
return url.includes('img.png');
192+
return true;
189193
},
190194
},
191195
},
@@ -262,8 +266,12 @@ module.exports = {
262266
// parsedImport.media - media query of `@import`
263267
// resourcePath - path to css file
264268

265-
// `@import` with `style.css` stay untouched
266-
return parsedImport.url.includes('style.css');
269+
// Don't handle `style.css` import
270+
if (parsedImport.url.includes('style.css')) {
271+
return false;
272+
}
273+
274+
return true;
267275
},
268276
},
269277
},

src/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
100100
}
101101

102102
function getFilter(filter, resourcePath, defaultFilter = null) {
103-
return (content) => {
104-
if (defaultFilter && !defaultFilter(content)) {
103+
return (item) => {
104+
if (defaultFilter && !defaultFilter(item)) {
105105
return false;
106106
}
107107

108108
if (typeof filter === 'function') {
109-
return !filter(content, resourcePath);
109+
return filter(item, resourcePath);
110110
}
111111

112112
return true;

test/import-option.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ describe('import option', () => {
6262
import: (parsedImport, resourcePath) => {
6363
expect(typeof resourcePath === 'string').toBe(true);
6464

65-
return parsedImport.url.includes('test.css');
65+
// Don't handle `test.css`
66+
if (parsedImport.url.includes('test.css')) {
67+
return false;
68+
}
69+
70+
return true;
6671
},
6772
},
6873
},

test/url-option.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ describe('url option', () => {
6262
url: (url, resourcePath) => {
6363
expect(typeof resourcePath === 'string').toBe(true);
6464

65-
return url.includes('img.png');
65+
// Don't handle `img.png`
66+
if (url.includes('img.png')) {
67+
return false;
68+
}
69+
70+
return true;
6671
},
6772
},
6873
},

0 commit comments

Comments
 (0)