Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 401be63

Browse files
insinmichael-ciniawsky
authored andcommitted
fix(utils/normalizeFallback): correctly pass all options to the default fallback (file-loader) (#139)
1 parent 75d9d8b commit 401be63

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/utils/normalizeFallback.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ function normalizeFallbackString(fallbackString, originalOptions) {
77
};
88
}
99

10-
// To remain consistent with version 1.0.1, pass the options which were provided to url-loader to the fallback loader.
11-
// Perhaps it would make sense to strip out ‒ or "consume" ‒ the options we know were meant for url-loader: limit and
12-
// mimetype.
10+
// To remain consistent with version 1.0.1, pass any other options which were provided to url-loader to the fallback loader.
11+
const { fallback, limit, mimetype, ...otherOptions } = originalOptions;
12+
1313
return {
1414
loader: fallbackString,
15-
query: originalOptions,
15+
query: otherOptions,
1616
};
1717
}
1818

@@ -35,9 +35,7 @@ function normalizeFallbackObject(fallbackObject) {
3535
export default function normalizeFallback(fallback, originalOptions) {
3636
// If no fallback was provided, use file-loader.
3737
if (!fallback) {
38-
return {
39-
loader: 'file-loader',
40-
};
38+
return normalizeFallbackString('file-loader', originalOptions);
4139
}
4240

4341
if (typeof fallback === 'string') {

test/options/__snapshots__/fallback.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ exports[`Options fallback {String} 2`] = `"module.exports = __webpack_public_pat
77
exports[`Options fallback {String} 3`] = `"module.exports = __webpack_public_path__ + \\"name-for-file-loader.png\\";"`;
88

99
exports[`Options fallback {String} 4`] = `"module.exports = __webpack_public_path__ + \\"name-for-file-loader.png\\";"`;
10+
11+
exports[`Options fallback {undefined} 1`] = `"module.exports = __webpack_public_path__ + \\"name-for-url-loader.png\\";"`;

test/options/fallback.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ describe('Options', () => {
2222
expect(source).toMatchSnapshot();
2323
});
2424

25+
test('{undefined}', async () => {
26+
const config = {
27+
loader: {
28+
test: /\.png$/,
29+
options: {
30+
limit: 100,
31+
name: 'name-for-url-loader.[ext]',
32+
},
33+
},
34+
};
35+
36+
const stats = await webpack('fixture.js', config);
37+
const { source } = stats.toJson().modules[0];
38+
39+
expect(source).toMatchSnapshot();
40+
});
41+
2542
// Version 1.0.1 passes options provided to url-loader to the fallback as well, so make sure that still works.
2643
test('{String}', async () => {
2744
const config = {

test/utils/__snapshots__/normalizeFallback.test.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ exports[`normalizeFallback string 1`] = `
2020
Object {
2121
"loader": "file-loader",
2222
"query": Object {
23-
"limit": 8192,
2423
"name": "name-for-url-loader.[ext]",
2524
},
2625
}
@@ -36,5 +35,8 @@ Object {
3635
exports[`normalizeFallback undefined 1`] = `
3736
Object {
3837
"loader": "file-loader",
38+
"query": Object {
39+
"name": "name-for-url-loader.[ext]",
40+
},
3941
}
4042
`;

0 commit comments

Comments
 (0)