@@ -29,6 +29,12 @@ const customProperties = require('postcss-custom-properties');
29
29
* require('sass-loader')
30
30
*/
31
31
32
+ interface PostcssUrlAsset {
33
+ url : string ;
34
+ hash : string ;
35
+ absolutePath : string ;
36
+ }
37
+
32
38
export function getStylesConfig ( wco : WebpackConfigOptions ) {
33
39
const { projectRoot, buildOptions, appConfig } = wco ;
34
40
@@ -47,7 +53,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
47
53
const baseHref = wco . buildOptions . baseHref || '' ;
48
54
const deployUrl = wco . buildOptions . deployUrl || '' ;
49
55
50
- const postcssPluginCreator = function ( ) {
56
+ const postcssPluginCreator = function ( loader : webpack . loader . LoaderContext ) {
51
57
// safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
52
58
const importantCommentRe = / @ p r e s e r v e | @ l i c e n [ c s ] e | [ @ # ] \s * s o u r c e (?: M a p p i n g ) ? U R L | ^ ! / i;
53
59
const minimizeOptions = {
@@ -59,14 +65,17 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
59
65
60
66
return [
61
67
postcssUrl ( {
62
- filter : ( { url } : { url : string } ) => url . startsWith ( '~' ) ,
63
- url : ( { url } : { url : string } ) => path . join ( projectRoot , 'node_modules' , url . substr ( 1 ) ) ,
68
+ filter : ( { url } : PostcssUrlAsset ) => url . startsWith ( '~' ) ,
69
+ url : ( { url } : PostcssUrlAsset ) => {
70
+ const fullPath = path . join ( projectRoot , 'node_modules' , url . substr ( 1 ) ) ;
71
+ return path . relative ( loader . context , fullPath ) . replace ( / \\ / g, '/' ) ;
72
+ }
64
73
} ) ,
65
74
postcssUrl ( [
66
75
{
67
76
// Only convert root relative URLs, which CSS-Loader won't process into require().
68
- filter : ( { url } : { url : string } ) => url . startsWith ( '/' ) && ! url . startsWith ( '//' ) ,
69
- url : ( { url } : { url : string } ) => {
77
+ filter : ( { url } : PostcssUrlAsset ) => url . startsWith ( '/' ) && ! url . startsWith ( '//' ) ,
78
+ url : ( { url } : PostcssUrlAsset ) => {
70
79
if ( deployUrl . match ( / : \/ \/ / ) || deployUrl . startsWith ( '/' ) ) {
71
80
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
72
81
return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ url } ` ;
@@ -83,7 +92,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
83
92
} ,
84
93
{
85
94
// TODO: inline .cur if not supporting IE (use browserslist to check)
86
- filter : ( asset : any ) => ! asset . hash && ! asset . absolutePath . endsWith ( '.cur' ) ,
95
+ filter : ( asset : PostcssUrlAsset ) => ! asset . hash && ! asset . absolutePath . endsWith ( '.cur' ) ,
87
96
url : 'inline' ,
88
97
// NOTE: maxSize is in KB
89
98
maxSize : 10
0 commit comments