Fix webpack config url in css

This commit is contained in:
Maxime GRIS
2017-04-21 20:18:46 +02:00
parent 0a93ebe96a
commit cea4be57ba

View File

@@ -136,7 +136,7 @@ module.exports = {
], ],
"fallback": "style-loader", "fallback": "style-loader",
"publicPath": "" "publicPath": ""
}) })
}, },
{ {
"include": [ "include": [
@@ -151,7 +151,7 @@ module.exports = {
], ],
"fallback": "style-loader", "fallback": "style-loader",
"publicPath": "" "publicPath": ""
}) })
}, },
{ {
"include": [ "include": [
@@ -166,7 +166,7 @@ module.exports = {
], ],
"fallback": "style-loader", "fallback": "style-loader",
"publicPath": "" "publicPath": ""
}) })
}, },
{ {
"include": [ "include": [
@@ -181,7 +181,7 @@ module.exports = {
], ],
"fallback": "style-loader", "fallback": "style-loader",
"publicPath": "" "publicPath": ""
}) })
}, },
{ {
"test": /\.ts$/, "test": /\.ts$/,
@@ -252,24 +252,24 @@ module.exports = {
"options": { "options": {
"postcss": [ "postcss": [
autoprefixer(), autoprefixer(),
postcssUrl({"url": (URL) => { postcssUrl({"url": (obj) => {
// Only convert root relative URLs, which CSS-Loader won't process into require(). // Only convert root relative URLs, which CSS-Loader won't process into require().
if (!URL.startsWith('/') || URL.startsWith('//')) { if (!obj.url.startsWith('/') || obj.url.startsWith('//')) {
return URL; return obj.url;
} }
if (deployUrl.match(/:\/\//)) { if (deployUrl.match(/:\/\//)) {
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is. // If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
return `${deployUrl.replace(/\/$/, '')}${URL}`; return `${deployUrl.replace(/\/$/, '')}${obj.url}`;
} }
else if (baseHref.match(/:\/\//)) { else if (baseHref.match(/:\/\//)) {
// If baseHref contains a scheme, include it as is. // If baseHref contains a scheme, include it as is.
return baseHref.replace(/\/$/, '') + return baseHref.replace(/\/$/, '') +
`/${deployUrl}/${URL}`.replace(/\/\/+/g, '/'); `/${deployUrl}/${obj.url}`.replace(/\/\/+/g, '/');
} }
else { else {
// Join together base-href, deploy-url and the original URL. // Join together base-href, deploy-url and the original URL.
// Also dedupe multiple slashes into single ones. // Also dedupe multiple slashes into single ones.
return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/'); return `/${baseHref}/${deployUrl}/${obj.url}`.replace(/\/\/+/g, '/');
} }
}}) }})
], ],