@@ -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
@@ -44,17 +50,20 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
44
50
const baseHref = wco . buildOptions . baseHref || '' ;
45
51
const deployUrl = wco . buildOptions . deployUrl || '' ;
46
52
47
- const postcssPluginCreator = function ( ) {
53
+ const postcssPluginCreator = function ( loader : webpack . loader . LoaderContext ) {
48
54
return [
49
55
postcssUrl ( {
50
- filter : ( { url } : { url : string } ) => url . startsWith ( '~' ) ,
51
- url : ( { url } : { url : string } ) => path . join ( projectRoot , 'node_modules' , url . substr ( 1 ) ) ,
56
+ filter : ( { url } : PostcssUrlAsset ) => url . startsWith ( '~' ) ,
57
+ url : ( { url } : PostcssUrlAsset ) => {
58
+ const fullPath = path . join ( projectRoot , 'node_modules' , url . substr ( 1 ) ) ;
59
+ return path . relative ( loader . context , fullPath ) . replace ( / \\ / g, '/' ) ;
60
+ }
52
61
} ) ,
53
62
postcssUrl ( [
54
63
{
55
64
// Only convert root relative URLs, which CSS-Loader won't process into require().
56
- filter : ( { url } : { url : string } ) => url . startsWith ( '/' ) && ! url . startsWith ( '//' ) ,
57
- url : ( { url } : { url : string } ) => {
65
+ filter : ( { url } : PostcssUrlAsset ) => url . startsWith ( '/' ) && ! url . startsWith ( '//' ) ,
66
+ url : ( { url } : PostcssUrlAsset ) => {
58
67
if ( deployUrl . match ( / : \/ \/ / ) || deployUrl . startsWith ( '/' ) ) {
59
68
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
60
69
return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ url } ` ;
@@ -71,7 +80,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
71
80
} ,
72
81
{
73
82
// TODO: inline .cur if not supporting IE (use browserslist to check)
74
- filter : ( asset : any ) => ! asset . hash && ! asset . absolutePath . endsWith ( '.cur' ) ,
83
+ filter : ( asset : PostcssUrlAsset ) => ! asset . hash && ! asset . absolutePath . endsWith ( '.cur' ) ,
75
84
url : 'inline' ,
76
85
// NOTE: maxSize is in KB
77
86
maxSize : 10
0 commit comments