Skip to content

Commit 01e8c76

Browse files
refactor: change function arguments of the import option (#1124)
BREAKING CHANGE: function arguments of the `import` option were changed, it is now `funciton(url, media, resourcePath) {}`
1 parent c153fe6 commit 01e8c76

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,11 @@ module.exports = {
262262
test: /\.css$/i,
263263
loader: 'css-loader',
264264
options: {
265-
import: (parsedImport, resourcePath) => {
266-
// parsedImport.url - url of `@import`
267-
// parsedImport.media - media query of `@import`
265+
import: (url, media, resourcePath) => {
268266
// resourcePath - path to css file
269267

270268
// Don't handle `style.css` import
271-
if (parsedImport.url.includes('style.css')) {
269+
if (url.includes('style.css')) {
272270
return false;
273271
}
274272

src/plugins/postcss-import-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default postcss.plugin(pluginName, (options) => async (css, result) => {
140140
media = valueParser.stringify(mediaNodes).trim().toLowerCase();
141141
}
142142

143-
if (options.filter && !options.filter({ url: normalizedUrl, media })) {
143+
if (options.filter && !options.filter(normalizedUrl, media)) {
144144
// eslint-disable-next-line no-continue
145145
continue;
146146
}

src/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ function requestify(url, rootContext) {
9393
}
9494

9595
function getFilter(filter, resourcePath) {
96-
return (item) => {
96+
return (...args) => {
9797
if (typeof filter === 'function') {
98-
return filter(item, resourcePath);
98+
return filter(...args, resourcePath);
9999
}
100100

101101
return true;

test/import-option.test.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ describe('"import" option', () => {
5252

5353
it('should work when "Function"', async () => {
5454
const compiler = getCompiler('./import/import.js', {
55-
import: (parsedImport, resourcePath) => {
56-
expect(typeof resourcePath === 'string').toBe(true);
55+
import: (url, media, resourcePath) => {
56+
expect(url).toBeDefined();
57+
58+
if (url === 'test-nested-media.css') {
59+
expect(media).toBeDefined();
60+
}
61+
62+
expect(resourcePath).toBeDefined();
5763

5864
// Don't handle `test.css`
59-
if (parsedImport.url.includes('test.css')) {
65+
if (url.includes('test.css')) {
6066
return false;
6167
}
6268

0 commit comments

Comments
 (0)