@@ -1046,6 +1046,7 @@ describe('rollup-plugin-html', () => {
1046
1046
const config = {
1047
1047
plugins : [
1048
1048
rollupPluginHTML ( {
1049
+ bundleAssetsFromCss : true ,
1049
1050
input : {
1050
1051
html : `
1051
1052
<html>
@@ -1069,8 +1070,8 @@ describe('rollup-plugin-html', () => {
1069
1070
const fontBold = output . find ( o => o . name === 'font-normal.woff2' ) ;
1070
1071
const style = output . find ( o => o . name === 'styles-with-fonts.css' ) ;
1071
1072
// It has emitted the font
1072
- expect ( ! ! fontBold ) . to . equal ( true ) ;
1073
- expect ( ! ! fontNormal ) . to . equal ( true ) ;
1073
+ expect ( fontBold ) . to . exist ;
1074
+ expect ( fontNormal ) . to . exist ;
1074
1075
// e.g. "font-normal-f0mNRiTD.woff2"
1075
1076
const regex = / a s s e t s \/ f o n t - n o r m a l - \w + \. w o f f 2 / ;
1076
1077
// It outputs the font to the assets folder
@@ -1085,6 +1086,7 @@ describe('rollup-plugin-html', () => {
1085
1086
const config = {
1086
1087
plugins : [
1087
1088
rollupPluginHTML ( {
1089
+ bundleAssetsFromCss : true ,
1088
1090
input : {
1089
1091
html : `
1090
1092
<html>
@@ -1108,7 +1110,7 @@ describe('rollup-plugin-html', () => {
1108
1110
const style = output . find ( o => o . name === 'node_modules-styles-with-fonts.css' ) ;
1109
1111
1110
1112
// It has emitted the font
1111
- expect ( ! ! font ) . to . equal ( true ) ;
1113
+ expect ( font ) . to . exist ;
1112
1114
// e.g. "font-normal-f0mNRiTD.woff2"
1113
1115
const regex = / a s s e t s \/ f o n t - n o r m a l - \w + \. w o f f 2 / ;
1114
1116
// It outputs the font to the assets folder
@@ -1123,6 +1125,7 @@ describe('rollup-plugin-html', () => {
1123
1125
const config = {
1124
1126
plugins : [
1125
1127
rollupPluginHTML ( {
1128
+ bundleAssetsFromCss : true ,
1126
1129
input : {
1127
1130
html : `
1128
1131
<html>
@@ -1146,4 +1149,74 @@ describe('rollup-plugin-html', () => {
1146
1149
const fonts = output . filter ( o => o . name === 'font-normal.woff2' ) ;
1147
1150
expect ( fonts . length ) . to . equal ( 1 ) ;
1148
1151
} ) ;
1152
+
1153
+ it ( 'handles images referenced from css' , async ( ) => {
1154
+ const config = {
1155
+ plugins : [
1156
+ rollupPluginHTML ( {
1157
+ bundleAssetsFromCss : true ,
1158
+ input : {
1159
+ html : `
1160
+ <html>
1161
+ <head>
1162
+ <link rel="stylesheet" href="./styles.css" />
1163
+ </head>
1164
+ <body>
1165
+ </body>
1166
+ </html>
1167
+ ` ,
1168
+ } ,
1169
+ rootDir : path . join ( __dirname , 'fixtures' , 'resolves-assets-in-styles-images' ) ,
1170
+ } ) ,
1171
+ ] ,
1172
+ } ;
1173
+
1174
+ const bundle = await rollup ( config ) ;
1175
+ const { output } = await bundle . generate ( outputConfig ) ;
1176
+
1177
+ expect ( output . find ( o => o . name === 'star.avif' ) ) . to . exist ;
1178
+ expect ( output . find ( o => o . name === 'star.gif' ) ) . to . exist ;
1179
+ expect ( output . find ( o => o . name === 'star.jpeg' ) ) . to . exist ;
1180
+ expect ( output . find ( o => o . name === 'star.jpg' ) ) . to . exist ;
1181
+ expect ( output . find ( o => o . name === 'star.png' ) ) . to . exist ;
1182
+ expect ( output . find ( o => o . name === 'star.svg' ) ) . to . exist ;
1183
+ expect ( output . find ( o => o . name === 'star.webp' ) ) . to . exist ;
1184
+
1185
+ const rewrittenCss = ( output . find ( o => o . name === 'styles.css' ) as OutputAsset ) . source
1186
+ . toString ( )
1187
+ . trim ( ) ;
1188
+ expect ( rewrittenCss ) . to . equal (
1189
+ `#a {
1190
+ background-image: url("assets/star-mrrzn5BV.svg");
1191
+ }
1192
+
1193
+ #b {
1194
+ background-image: url("assets/star-mrrzn5BV.svg#foo");
1195
+ }
1196
+
1197
+ #c {
1198
+ background-image: url("assets/star-eErsO14u.png");
1199
+ }
1200
+
1201
+ #d {
1202
+ background-image: url("assets/star-yqfHyXQC.jpg");
1203
+ }
1204
+
1205
+ #e {
1206
+ background-image: url("assets/star-G_i5Rpoh.jpeg");
1207
+ }
1208
+
1209
+ #f {
1210
+ background-image: url("assets/star-l7b58t3m.webp");
1211
+ }
1212
+
1213
+ #g {
1214
+ background-image: url("assets/star-P4TYRBwL.gif");
1215
+ }
1216
+
1217
+ #h {
1218
+ background-image: url("assets/star-H06WHrYy.avif");
1219
+ }` . trim ( ) ,
1220
+ ) ;
1221
+ } ) ;
1149
1222
} ) ;
0 commit comments