@@ -20,19 +20,22 @@ HashBundlePlugin.prototype.apply = (compiler) => {
20
20
if ( ! stats . errors . length ) {
21
21
const htmlFileName = 'index.html' ;
22
22
const html = fs . readFileSync ( path . join ( __dirname , htmlFileName ) , 'utf8' ) ;
23
- const htmlOutput = html . replace ( / \/ b u i l d \/ .? b u n d l e \. j s / , `${ '/build/' } ${ stats . hash } ${ '.bundle.js' } ` ) ;
23
+ const htmlOutput = html . replace ( / \/ b u i l d \/ .? m a i n \. j s / , `${ '/build/' } ${ stats . hash } ${ '.main.js' } ` ) ;
24
+ const vendorOutput = htmlOutput . replace ( / \/ b u i l d \/ .? v e n d o r \. j s / , `${ '/build/' } ${ stats . hash } ${ '.vendor.js' } ` ) ;
24
25
25
- fs . writeFileSync ( path . join ( __dirname , htmlFileName ) , htmlOutput ) ;
26
+ fs . writeFileSync ( path . join ( __dirname , htmlFileName ) , vendorOutput ) ;
27
+ //fs.writeFileSync(path.join(__dirname, htmlFileName), vendorOutput);
26
28
}
27
29
} ) ;
28
30
} ;
29
31
30
32
const config = {
31
33
entry : [ 'babel-polyfill' , path . resolve ( __dirname , 'src' ) ] ,
32
34
output : {
33
- filename : `${ isProd ? '[hash].' : '' } bundle .js` ,
35
+ filename : `${ isProd ? '[hash].' : '' } [name] .js` ,
34
36
path : path . resolve ( __dirname , 'build' ) ,
35
37
publicPath : '/build/' ,
38
+ chunkFilename : '[chunkhash:8].[name].chunk.js' ,
36
39
} ,
37
40
resolve : {
38
41
extensions : [ '.jsx' , '.js' , '.css' , '.json' , 'scss' ] ,
@@ -65,6 +68,13 @@ const config = {
65
68
} ] ,
66
69
} ,
67
70
plugins : [
71
+ new webpack . optimize . CommonsChunkPlugin ( {
72
+ name : 'vendor' ,
73
+ minChunks : function ( module ) {
74
+ // 该配置假定你引入的 vendor 存在于 node_modules 目录中
75
+ return module . context && module . context . indexOf ( 'node_modules' ) !== - 1 ;
76
+ }
77
+ } ) ,
68
78
new webpack . LoaderOptionsPlugin ( {
69
79
options : {
70
80
postcss : [
0 commit comments