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

Commit

Permalink
fix(utils/normalizeFallback): correctly pass all options to the def…
Browse files Browse the repository at this point in the history
…ault fallback (`file-loader`) (#139)
  • Loading branch information
insin authored and michael-ciniawsky committed Aug 15, 2018
1 parent 75d9d8b commit 401be63
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/utils/normalizeFallback.js
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
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
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
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]",
},
}
`;

0 comments on commit 401be63

Please sign in to comment.