Skip to content

Commit ab65f50

Browse files
committed
Optimize webpack entries for demo
1 parent 5fbb532 commit ab65f50

File tree

1 file changed

+44
-76
lines changed

1 file changed

+44
-76
lines changed

examples/webpack.config.js

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath)
1111
export default function webpackConfig(env, argv) {
1212
const isProduction = argv.mode === 'production'
1313

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 = {
1527
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
2529
},
2630
watchOptions: {
2731
ignored: /node_modules/
@@ -52,78 +56,13 @@ export default function webpackConfig(env, argv) {
5256
resolve: {
5357
extensions: ['.js', '.css']
5458
},
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-
},
6659
context: appDirectory,
6760
plugins: [
6861
new MiniCssExtractPlugin({
6962
filename: 'styles/[name].css',
7063
chunkFilename: 'styles/[name].css'
7164
}),
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()
12766
],
12867
stats: {
12968
assets: true,
@@ -161,4 +100,33 @@ export default function webpackConfig(env, argv) {
161100
splitChunks: false
162101
}
163102
}
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
164132
}

0 commit comments

Comments
 (0)