mirror of https://github.com/webpack/webpack.git
				
				
				
			
		
			
				
	
	
	
		
			1.3 KiB
		
	
	
	
	
	
			
		
		
	
	
			1.3 KiB
		
	
	
	
	
	
This example illustrates a very simple case of Code Splitting with require.ensure.
- aand- bare required normally via CommonJS
- cis made available(,but doesn't get execute) through the- require.ensurearray.- webpack will load it on demand
 
- band- dare required via CommonJs in the- require.ensurecallback- webpack detects that these are in the on-demand-callback and
- will load them on demand
- webpack's optimizer can optimize baway- as it is already available through the parent chunks
 
 
You can see that webpack outputs two files/chunks:
- output.jsis the entry chunk and contains- the module system
- chunk loading logic
- the entry point example.js
- module a
- module b
 
- 1.output.jsis an additional chunk (on-demand loaded) and contains- module c
- module d
 
- module 
You can see that chunks are loaded via JSONP. The additional chunks are pretty small and minimize well.
example.js
_{{example.js}}_
dist/output.js
_{{dist/output.js}}_
dist/node_modules_c_js-node_modules_d_js.output.js
_{{dist/node_modules_c_js-node_modules_d_js.output.js}}_
Minimized
_{{production:dist/node_modules_c_js-node_modules_d_js.output.js}}_
Info
Unoptimized
_{{stdout}}_
Production mode
_{{production:stdout}}_