diff --git a/README.md b/README.md index daec7159..7dcaae67 100644 --- a/README.md +++ b/README.md @@ -262,13 +262,11 @@ module.exports = { test: /\.css$/i, loader: 'css-loader', options: { - import: (parsedImport, resourcePath) => { - // parsedImport.url - url of `@import` - // parsedImport.media - media query of `@import` + import: (url, media, resourcePath) => { // resourcePath - path to css file // Don't handle `style.css` import - if (parsedImport.url.includes('style.css')) { + if (url.includes('style.css')) { return false; } diff --git a/src/plugins/postcss-import-parser.js b/src/plugins/postcss-import-parser.js index 71dc394c..297c70cf 100644 --- a/src/plugins/postcss-import-parser.js +++ b/src/plugins/postcss-import-parser.js @@ -140,7 +140,7 @@ export default postcss.plugin(pluginName, (options) => async (css, result) => { media = valueParser.stringify(mediaNodes).trim().toLowerCase(); } - if (options.filter && !options.filter({ url: normalizedUrl, media })) { + if (options.filter && !options.filter(normalizedUrl, media)) { // eslint-disable-next-line no-continue continue; } diff --git a/src/utils.js b/src/utils.js index 506aac47..6441cc7f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -93,9 +93,9 @@ function requestify(url, rootContext) { } function getFilter(filter, resourcePath) { - return (item) => { + return (...args) => { if (typeof filter === 'function') { - return filter(item, resourcePath); + return filter(...args, resourcePath); } return true; diff --git a/test/import-option.test.js b/test/import-option.test.js index 6a3d4198..6a154754 100644 --- a/test/import-option.test.js +++ b/test/import-option.test.js @@ -52,11 +52,17 @@ describe('"import" option', () => { it('should work when "Function"', async () => { const compiler = getCompiler('./import/import.js', { - import: (parsedImport, resourcePath) => { - expect(typeof resourcePath === 'string').toBe(true); + import: (url, media, resourcePath) => { + expect(url).toBeDefined(); + + if (url === 'test-nested-media.css') { + expect(media).toBeDefined(); + } + + expect(resourcePath).toBeDefined(); // Don't handle `test.css` - if (parsedImport.url.includes('test.css')) { + if (url.includes('test.css')) { return false; }