File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
plugin/react-ssr-dynamic-chunk-webpack-plugin Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
2+ const ReactSSRDynamicChunkPlugin = require ( './plugin/react-ssr-dynamic-chunk-webpack-plugin' ) ;
3+ exports . vuessrchunk = {
4+ type : [ 'server' ] ,
5+ name : new ReactSSRDynamicChunkPlugin ( ) ,
6+ args : {
7+ }
8+ } ;
29
310exports . modulereplacement = false ;
411
512exports . ignore = false ;
13+
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const path = require ( 'path' ) ;
3+ const fs = require ( 'fs' ) ;
4+ const mkdirp = require ( 'mkdirp' ) ;
5+
6+ class ReactSSRDynamicChunkPlugin {
7+ constructor ( opts ) {
8+ this . opts = Object . assign ( { } , { chunk : true } , opts ) ;
9+ }
10+
11+ apply ( compiler ) {
12+ compiler . hooks . emit . tap ( 'ReactSSRDynamicChunkPlugin' , ( compilation , callback ) => {
13+ const buildPath = compilation . options . output . path ;
14+
15+ if ( ! fs . existsSync ( buildPath ) ) {
16+ mkdirp . sync ( buildPath ) ;
17+ }
18+
19+ compilation . chunks . forEach ( chunk => {
20+ if ( ! this . opts . chunk ) {
21+ return ;
22+ }
23+
24+ const asyncChunks = chunk . getAllAsyncChunks ( ) ;
25+
26+ asyncChunks && asyncChunks . forEach ( asyncChunk => {
27+ asyncChunk . files . forEach ( filename => {
28+ const filepath = path . join ( buildPath , filename ) ;
29+ const source = compilation . assets [ filename ] . source ( ) ;
30+ fs . writeFileSync ( filepath , source , 'utf8' ) ;
31+ } ) ;
32+ } )
33+ } ) ;
34+ callback && callback ( ) ;
35+ } ) ;
36+ }
37+ }
38+
39+ module . exports = ReactSSRDynamicChunkPlugin ;
You can’t perform that action at this time.
0 commit comments