Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invert Function behavior for url and import options #939

Merged
merged 1 commit into from May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -183,9 +183,13 @@ module.exports = {
options: {
url: (url, resourcePath) => {
// resourcePath - path to css file

// Don't handle `img.png` urls
if (url.includes('img.png')) {
return false;
}

// `url()` with `img.png` stay untouched
return url.includes('img.png');
return true;
},
},
},
Expand Down Expand Up @@ -262,8 +266,12 @@ module.exports = {
// parsedImport.media - media query of `@import`
// resourcePath - path to css file

// `@import` with `style.css` stay untouched
return parsedImport.url.includes('style.css');
// Don't handle `style.css` import
if (parsedImport.url.includes('style.css')) {
return false;
}

return true;
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Expand Up @@ -100,13 +100,13 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
}

function getFilter(filter, resourcePath, defaultFilter = null) {
return (content) => {
if (defaultFilter && !defaultFilter(content)) {
return (item) => {
if (defaultFilter && !defaultFilter(item)) {
return false;
}

if (typeof filter === 'function') {
return !filter(content, resourcePath);
return filter(item, resourcePath);
}

return true;
Expand Down
7 changes: 6 additions & 1 deletion test/import-option.test.js
Expand Up @@ -62,7 +62,12 @@ describe('import option', () => {
import: (parsedImport, resourcePath) => {
expect(typeof resourcePath === 'string').toBe(true);

return parsedImport.url.includes('test.css');
// Don't handle `test.css`
if (parsedImport.url.includes('test.css')) {
return false;
}

return true;
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion test/url-option.test.js
Expand Up @@ -62,7 +62,12 @@ describe('url option', () => {
url: (url, resourcePath) => {
expect(typeof resourcePath === 'string').toBe(true);

return url.includes('img.png');
// Don't handle `img.png`
if (url.includes('img.png')) {
return false;
}

return true;
},
},
},
Expand Down