@@ -134,6 +134,69 @@ describe('build', () => {
134134 assertOutputHashContentChange ( result [ 0 ] , result [ 1 ] )
135135 } )
136136
137+ test . for ( [
138+ [ true , true ] ,
139+ [ true , false ] ,
140+ [ false , true ] ,
141+ [ false , false ] ,
142+ [ 'auto' , true ] ,
143+ [ 'auto' , false ] ,
144+ ] as const ) (
145+ 'large json object files should have tree-shaking (json.stringify: %s, json.namedExports: %s)' ,
146+ async ( [ stringify , namedExports ] ) => {
147+ const esBundle = ( await build ( {
148+ mode : 'development' ,
149+ root : resolve ( __dirname , 'packages/build-project' ) ,
150+ logLevel : 'silent' ,
151+ json : { stringify, namedExports } ,
152+ build : {
153+ minify : false ,
154+ modulePreload : { polyfill : false } ,
155+ write : false ,
156+ } ,
157+ plugins : [
158+ {
159+ name : 'test' ,
160+ resolveId ( id ) {
161+ if (
162+ id === 'entry.js' ||
163+ id === 'object.json' ||
164+ id === 'array.json'
165+ ) {
166+ return '\0' + id
167+ }
168+ } ,
169+ load ( id ) {
170+ if ( id === '\0entry.js' ) {
171+ return `
172+ import object from 'object.json';
173+ import array from 'array.json';
174+ console.log();
175+ `
176+ }
177+ if ( id === '\0object.json' ) {
178+ return `
179+ {"value": {"${ stringify } _${ namedExports } ":"JSON_OBJ${ '_' . repeat ( 10_000 ) } "}}
180+ `
181+ }
182+ if ( id === '\0array.json' ) {
183+ return `
184+ ["${ stringify } _${ namedExports } ","JSON_ARR${ '_' . repeat ( 10_000 ) } "]
185+ `
186+ }
187+ } ,
188+ } ,
189+ ] ,
190+ } ) ) as RollupOutput
191+
192+ const foo = esBundle . output . find (
193+ ( chunk ) => chunk . type === 'chunk' && chunk . isEntry ,
194+ ) as OutputChunk
195+ expect ( foo . code ) . not . contains ( 'JSON_ARR' )
196+ expect ( foo . code ) . not . contains ( 'JSON_OBJ' )
197+ } ,
198+ )
199+
137200 test ( 'external modules should not be hoisted in library build' , async ( ) => {
138201 const [ esBundle ] = ( await build ( {
139202 logLevel : 'silent' ,
0 commit comments