@@ -25,7 +25,9 @@ describe('compiler', () => {
2525 | 'vitePlugins'
2626 | 'tsconfigPaths'
2727 | 'basePath'
28- | 'getAllCss' ,
28+ | 'getAllCss'
29+ | 'assetsInlineLimit'
30+ | 'assetsNoInlineLimit' ,
2931 ReturnType < typeof createCompiler >
3032 > ;
3133
@@ -83,6 +85,22 @@ describe('compiler', () => {
8385 getAllCss : createCompiler ( {
8486 root : __dirname ,
8587 } ) ,
88+ assetsInlineLimit : createCompiler ( {
89+ root : __dirname ,
90+ viteConfig : {
91+ build : {
92+ assetsInlineLimit : 512 ,
93+ } ,
94+ } ,
95+ } ) ,
96+ assetsNoInlineLimit : createCompiler ( {
97+ root : __dirname ,
98+ viteConfig : {
99+ build : {
100+ assetsInlineLimit : 0 ,
101+ } ,
102+ } ,
103+ } ) ,
86104 } ;
87105 } ) ;
88106
@@ -583,4 +601,54 @@ describe('compiler', () => {
583601
584602 ` ) ;
585603 } ) ;
604+
605+ test ( 'setting build.assetsInlineLimit = 0 should disable inlining' , async ( ) => {
606+ const compiler = compilers . assetsNoInlineLimit ;
607+
608+ const cssPath = path . join (
609+ __dirname ,
610+ 'fixtures/assets-inline-limit/styles.css.ts' ,
611+ ) ;
612+ const output = await compiler . processVanillaFile ( cssPath ) ;
613+ const { css } = compiler . getCssForFile ( cssPath ) ;
614+
615+ expect ( output . source ) . toMatchInlineSnapshot ( `
616+ import '{{__dirname}}/fixtures/assets-inline-limit/styles.css.ts.vanilla.css';
617+ export var square = 'styles_square__upl4cj0';
618+ ` ) ;
619+
620+ expect ( css ) . toMatchInlineSnapshot ( `
621+ .styles_square__upl4cj0 {
622+ width: 100px;
623+ height: 100px;
624+ background-image: url("/fixtures/assets-inline-limit/square.svg");
625+ background-size: cover;
626+ }
627+ ` ) ;
628+ } ) ;
629+
630+ test ( 'setting build.assetsInlineLimit = 512 should inline assets appropriately' , async ( ) => {
631+ const compiler = compilers . assetsInlineLimit ;
632+
633+ const cssPath = path . join (
634+ __dirname ,
635+ 'fixtures/assets-inline-limit/styles.css.ts' ,
636+ ) ;
637+ const output = await compiler . processVanillaFile ( cssPath ) ;
638+ const { css } = compiler . getCssForFile ( cssPath ) ;
639+
640+ expect ( output . source ) . toMatchInlineSnapshot ( `
641+ import '{{__dirname}}/fixtures/assets-inline-limit/styles.css.ts.vanilla.css';
642+ export var square = 'styles_square__upl4cj0';
643+ ` ) ;
644+
645+ expect ( css ) . toMatchInlineSnapshot ( `
646+ .styles_square__upl4cj0 {
647+ width: 100px;
648+ height: 100px;
649+ background-image: url("data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3c!--%20Uploaded%20to:%20SVG%20Repo,%20www.svgrepo.com,%20Generator:%20SVG%20Repo%20Mixer%20Tools%20--%3e%3csvg%20width='800px'%20height='800px'%20viewBox='0%200%2016%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20x='1'%20y='1'%20width='14'%20height='14'%20fill='%23000000'/%3e%3c/svg%3e");
650+ background-size: cover;
651+ }
652+ ` ) ;
653+ } ) ;
586654} ) ;
0 commit comments