-
Notifications
You must be signed in to change notification settings - Fork 21
/
postcss.config.js
33 lines (31 loc) · 1.5 KB
/
postcss.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import postcssUrl from 'postcss-url';
import autoprefixer from 'autoprefixer';
const BASE_HREF = '';
const DEPLOY_URL = '';
export default () => {
return [
postcssUrl({
url: ({ url }) => {
// Only convert root relative URLs, which CSS-Loader won't process into require().
if (!url.startsWith('/') || url.startsWith('//')) {
return url.replace(/\/\/+/g, '/');
}
if (DEPLOY_URL.match(/:\/\//)) {
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
console.log('1', `${DEPLOY_URL.replace(/\/$/, '')}${url}`);
return `${DEPLOY_URL.replace(/\/$/, '')}${url}`;
} else if (BASE_HREF.match(/:\/\//)) {
console.log('2', BASE_HREF.replace(/\/$/, '') + `/${DEPLOY_URL}/${url}`.replace(/\/\/+/g, '/'));
// If baseHref contains a scheme, include it as is.
return BASE_HREF.replace(/\/$/, '') + `/${DEPLOY_URL}/${url}`.replace(/\/\/+/g, '/');
} else {
// Join together base-href, deploy-url and the original URL.
// Also dedupe multiple slashes into single ones.
console.log('3', `/${BASE_HREF}/${DEPLOY_URL}/${url}`.replace(/\/\/+/g, '/'));
return `/${BASE_HREF}/${DEPLOY_URL}/${url}`.replace(/\/\/+/g, '/');
}
},
}),
autoprefixer(),
];
};