Fix flash from url on windows

Changelog-entry: Fix flash from url on windows
Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-06-04 19:42:41 +02:00
parent 29e2e9c657
commit b749c2d45a

View File

@ -96,11 +96,15 @@ interface ReplacementRule {
replace: string | (() => string); replace: string | (() => string);
} }
function slashOrAntislash(pattern: RegExp): RegExp {
return new RegExp(pattern.source.replace(/\\\//g, '(\\/|\\\\)'));
}
function replace(test: RegExp, ...replacements: ReplacementRule[]) { function replace(test: RegExp, ...replacements: ReplacementRule[]) {
return { return {
loader: 'string-replace-loader', loader: 'string-replace-loader',
// Handle windows path separators // Handle windows path separators
test: new RegExp(test.source.replace(/\\\//g, '(\\/|\\\\)')), test: slashOrAntislash(test),
options: { multiple: replacements.map((r) => ({ ...r, strict: true })) }, options: { multiple: replacements.map((r) => ({ ...r, strict: true })) },
}; };
} }
@ -223,7 +227,7 @@ const commonConfig = {
// Force axios to use http.js, not xhr.js as we need stream support // Force axios to use http.js, not xhr.js as we need stream support
// (it's package.json file replaces http with xhr for browser targets). // (it's package.json file replaces http with xhr for browser targets).
new NormalModuleReplacementPlugin( new NormalModuleReplacementPlugin(
/node_modules\/axios\/lib\/adapters\/xhr\.js/, slashOrAntislash(/node_modules\/axios\/lib\/adapters\/xhr\.js/),
'./http.js', './http.js',
), ),
], ],