@@ -29,6 +29,12 @@ const customProperties = require('postcss-custom-properties');
2929 * require('sass-loader')
3030 */
3131
32+ interface PostcssUrlAsset {
33+ url : string ;
34+ hash : string ;
35+ absolutePath : string ;
36+ }
37+
3238export function getStylesConfig ( wco : WebpackConfigOptions ) {
3339 const { projectRoot, buildOptions, appConfig } = wco ;
3440
@@ -44,17 +50,20 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4450 const baseHref = wco . buildOptions . baseHref || '' ;
4551 const deployUrl = wco . buildOptions . deployUrl || '' ;
4652
47- const postcssPluginCreator = function ( ) {
53+ const postcssPluginCreator = function ( loader : webpack . loader . LoaderContext ) {
4854 return [
4955 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+ }
5261 } ) ,
5362 postcssUrl ( [
5463 {
5564 // 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 ) => {
5867 if ( deployUrl . match ( / : \/ \/ / ) || deployUrl . startsWith ( '/' ) ) {
5968 // If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
6069 return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ url } ` ;
@@ -71,7 +80,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
7180 } ,
7281 {
7382 // 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' ) ,
7584 url : 'inline' ,
7685 // NOTE: maxSize is in KB
7786 maxSize : 10
0 commit comments