@@ -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
@@ -47,7 +53,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4753 const baseHref = wco . buildOptions . baseHref || '' ;
4854 const deployUrl = wco . buildOptions . deployUrl || '' ;
4955
50- const postcssPluginCreator = function ( ) {
56+ const postcssPluginCreator = function ( loader : webpack . loader . LoaderContext ) {
5157 // safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
5258 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;
5359 const minimizeOptions = {
@@ -59,14 +65,17 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
5965
6066 return [
6167 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+ }
6473 } ) ,
6574 postcssUrl ( [
6675 {
6776 // 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 ) => {
7079 if ( deployUrl . match ( / : \/ \/ / ) || deployUrl . startsWith ( '/' ) ) {
7180 // If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
7281 return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ url } ` ;
@@ -83,7 +92,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
8392 } ,
8493 {
8594 // 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' ) ,
8796 url : 'inline' ,
8897 // NOTE: maxSize is in KB
8998 maxSize : 10
0 commit comments