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

fix(utils/normalizeFallback): correctly pass all options to the default fallback (file-loader) #139

Merged
merged 2 commits into from
Aug 15, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/utils/normalizeFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ function normalizeFallbackString(fallbackString, originalOptions) {
};
}

// To remain consistent with version 1.0.1, pass the options which were provided to url-loader to the fallback loader.
// Perhaps it would make sense to strip out ‒ or "consume" ‒ the options we know were meant for url-loader: limit and
// mimetype.
// To remain consistent with version 1.0.1, pass any other options which were provided to url-loader to the fallback loader.
const { fallback, limit, mimetype, ...otherOptions } = originalOptions;

return {
loader: fallbackString,
query: originalOptions,
query: otherOptions,
};
}

Expand All @@ -35,9 +35,7 @@ function normalizeFallbackObject(fallbackObject) {
export default function normalizeFallback(fallback, originalOptions) {
// If no fallback was provided, use file-loader.
if (!fallback) {
return {
loader: 'file-loader',
};
return normalizeFallbackString('file-loader', originalOptions);
}

if (typeof fallback === 'string') {
Expand Down
2 changes: 2 additions & 0 deletions test/options/__snapshots__/fallback.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ exports[`Options fallback {String} 2`] = `"module.exports = __webpack_public_pat
exports[`Options fallback {String} 3`] = `"module.exports = __webpack_public_path__ + \\"name-for-file-loader.png\\";"`;

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

exports[`Options fallback {undefined} 1`] = `"module.exports = __webpack_public_path__ + \\"name-for-url-loader.png\\";"`;
17 changes: 17 additions & 0 deletions test/options/fallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ describe('Options', () => {
expect(source).toMatchSnapshot();
});

test('{undefined}', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
limit: 100,
name: 'name-for-url-loader.[ext]',
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});

// Version 1.0.1 passes options provided to url-loader to the fallback as well, so make sure that still works.
test('{String}', async () => {
const config = {
Expand Down
4 changes: 3 additions & 1 deletion test/utils/__snapshots__/normalizeFallback.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ exports[`normalizeFallback string 1`] = `
Object {
"loader": "file-loader",
"query": Object {
"limit": 8192,
"name": "name-for-url-loader.[ext]",
},
}
Expand All @@ -36,5 +35,8 @@ Object {
exports[`normalizeFallback undefined 1`] = `
Object {
"loader": "file-loader",
"query": Object {
"name": "name-for-url-loader.[ext]",
},
}
`;