@@ -42,6 +42,7 @@ import {
42
42
processSrcSet
43
43
} from '../utils'
44
44
import { emptyCssComments } from '../utils'
45
+ import type { Logger } from '../logger'
45
46
import { addToHTMLProxyTransformResult } from './html'
46
47
import {
47
48
assetUrlRE ,
@@ -748,7 +749,8 @@ async function compileCSS(
748
749
}
749
750
postcssPlugins . push (
750
751
UrlRewritePostcssPlugin ( {
751
- replacer : urlReplacer
752
+ replacer : urlReplacer ,
753
+ logger : config . logger
752
754
} ) as PostCSS . Plugin
753
755
)
754
756
@@ -980,6 +982,7 @@ const cssImageSetRE = /(?<=image-set\()((?:[\w\-]+\([^\)]*\)|[^)])*)(?=\))/
980
982
981
983
const UrlRewritePostcssPlugin : PostCSS . PluginCreator < {
982
984
replacer : CssUrlReplacer
985
+ logger : Logger
983
986
} > = ( opts ) => {
984
987
if ( ! opts ) {
985
988
throw new Error ( 'base or replace is required' )
@@ -990,11 +993,19 @@ const UrlRewritePostcssPlugin: PostCSS.PluginCreator<{
990
993
Once ( root ) {
991
994
const promises : Promise < void > [ ] = [ ]
992
995
root . walkDecls ( ( declaration ) => {
996
+ const importer = declaration . source ?. input . file
997
+ if ( ! importer ) {
998
+ opts . logger . warnOnce (
999
+ '\nA PostCSS plugin did not pass the `from` option to `postcss.parse`. ' +
1000
+ 'This may cause imported assets to be incorrectly transformed. ' +
1001
+ "If you've recently added a PostCSS plugin that raised this warning, " +
1002
+ 'please contact the package author to fix the issue.'
1003
+ )
1004
+ }
993
1005
const isCssUrl = cssUrlRE . test ( declaration . value )
994
1006
const isCssImageSet = cssImageSetRE . test ( declaration . value )
995
1007
if ( isCssUrl || isCssImageSet ) {
996
1008
const replacerForDeclaration = ( rawUrl : string ) => {
997
- const importer = declaration . source ?. input . file
998
1009
return opts . replacer ( rawUrl , importer )
999
1010
}
1000
1011
const rewriterToUse = isCssImageSet
0 commit comments