@@ -11,17 +11,21 @@ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath)
11
11
export default function webpackConfig ( env , argv ) {
12
12
const isProduction = argv . mode === 'production'
13
13
14
- return {
14
+ const entries = [
15
+ 'home' ,
16
+ 'html5' ,
17
+ 'html5-hls' ,
18
+ 'html5-ima' ,
19
+ 'html5-sticky' ,
20
+ 'audio' ,
21
+ 'youtube' ,
22
+ 'vimeo' ,
23
+ 'dailymotion'
24
+ ]
25
+
26
+ const config = {
15
27
entry : {
16
- home : resolveApp ( 'examples/home/config.js' ) ,
17
- html5 : resolveApp ( 'examples/html5/config.js' ) ,
18
- 'html5-hls' : resolveApp ( 'examples/html5-hls/config.js' ) ,
19
- 'html5-ima' : resolveApp ( 'examples/html5-ima/config.js' ) ,
20
- 'html5-sticky' : resolveApp ( 'examples/html5-sticky/config.js' ) ,
21
- audio : resolveApp ( 'examples/audio/config.js' ) ,
22
- youtube : resolveApp ( 'examples/youtube/config.js' ) ,
23
- vimeo : resolveApp ( 'examples/vimeo/config.js' ) ,
24
- dailymotion : resolveApp ( 'examples/dailymotion/config.js' )
28
+ // Entries are populated at the end of the function
25
29
} ,
26
30
watchOptions : {
27
31
ignored : / n o d e _ m o d u l e s /
@@ -52,78 +56,13 @@ export default function webpackConfig(env, argv) {
52
56
resolve : {
53
57
extensions : [ '.js' , '.css' ]
54
58
} ,
55
- devServer : {
56
- static : {
57
- directory : resolveApp ( 'examples' )
58
- } ,
59
- historyApiFallback : true ,
60
- port : 3000 ,
61
- compress : true ,
62
- hot : true
63
- // host: '0.0.0.0',
64
- // https: true, // For IMA plugin
65
- } ,
66
59
context : appDirectory ,
67
60
plugins : [
68
61
new MiniCssExtractPlugin ( {
69
62
filename : 'styles/[name].css' ,
70
63
chunkFilename : 'styles/[name].css'
71
64
} ) ,
72
- new webpack . optimize . ModuleConcatenationPlugin ( ) ,
73
- new HtmlWebpackPlugin ( {
74
- filename : 'index.html' ,
75
- template : resolveApp ( 'examples/home/index.html' ) ,
76
- chunks : [ 'home' ]
77
- } ) ,
78
- new HtmlWebpackPlugin ( {
79
- filename : 'html5/index.html' ,
80
- template : resolveApp ( 'examples/html5/index.html' ) ,
81
- chunks : [ 'html5' ] ,
82
- publicPath : '../'
83
- } ) ,
84
- new HtmlWebpackPlugin ( {
85
- filename : 'html5-hls/index.html' ,
86
- template : resolveApp ( 'examples/html5-hls/index.html' ) ,
87
- chunks : [ 'html5-hls' ] ,
88
- publicPath : '../'
89
- } ) ,
90
- new HtmlWebpackPlugin ( {
91
- filename : 'html5-ima/index.html' ,
92
- template : resolveApp ( 'examples/html5-ima/index.html' ) ,
93
- chunks : [ 'html5-ima' ] ,
94
- publicPath : '../'
95
- } ) ,
96
- new HtmlWebpackPlugin ( {
97
- filename : 'html5-sticky/index.html' ,
98
- template : resolveApp ( 'examples/html5-sticky/index.html' ) ,
99
- chunks : [ 'html5-sticky' ] ,
100
- publicPath : '../'
101
- } ) ,
102
- new HtmlWebpackPlugin ( {
103
- filename : 'youtube/index.html' ,
104
- template : resolveApp ( 'examples/youtube/index.html' ) ,
105
- chunks : [ 'youtube' ] ,
106
- publicPath : '../'
107
- } ) ,
108
- new HtmlWebpackPlugin ( {
109
- filename : 'vimeo/index.html' ,
110
- template : resolveApp ( 'examples/vimeo/index.html' ) ,
111
- chunks : [ 'vimeo' ] ,
112
- publicPath : '../'
113
- } ) ,
114
- new HtmlWebpackPlugin ( {
115
- filename : 'dailymotion/index.html' ,
116
- template : resolveApp ( 'examples/dailymotion/index.html' ) ,
117
- chunks : [ 'dailymotion' ] ,
118
- publicPath : '../'
119
- } ) ,
120
- new HtmlWebpackPlugin ( {
121
- filename : 'audio/index.html' ,
122
- template : resolveApp ( 'examples/audio/index.html' ) ,
123
- chunks : [ 'audio' ] ,
124
- publicPath : '../'
125
- } ) ,
126
- ...( isProduction ? [ new webpack . ProgressPlugin ( ) ] : [ ] )
65
+ new webpack . optimize . ModuleConcatenationPlugin ( )
127
66
] ,
128
67
stats : {
129
68
assets : true ,
@@ -161,4 +100,33 @@ export default function webpackConfig(env, argv) {
161
100
splitChunks : false
162
101
}
163
102
}
103
+
104
+ if ( ! isProduction ) {
105
+ config . plugins . push ( new webpack . ProgressPlugin ( ) )
106
+ config . devServer = {
107
+ static : {
108
+ directory : resolveApp ( 'examples' )
109
+ } ,
110
+ historyApiFallback : true ,
111
+ port : 3000 ,
112
+ compress : true ,
113
+ hot : true
114
+ // host: '0.0.0.0',
115
+ // https: true, // For IMA plugin
116
+ }
117
+ }
118
+
119
+ entries . forEach ( ( key ) => {
120
+ config . entry [ key ] = resolveApp ( `examples/${ key } /config.js` )
121
+ config . plugins . push (
122
+ new HtmlWebpackPlugin ( {
123
+ filename : key === 'home' ? 'index.html' : `${ key } /index.html` ,
124
+ template : resolveApp ( `examples/${ key } /index.html` ) ,
125
+ chunks : [ key ] ,
126
+ minify : isProduction
127
+ } )
128
+ )
129
+ } )
130
+
131
+ return config
164
132
}
0 commit comments