UNPKG

1.61 kBJavaScriptView Raw
1var fs = require('fs')
2var webpack = require('webpack')
3var merge = require('webpack-merge')
4var baseConfig = require('./webpack.base.conf')
5var HtmlWebpackPlugin = require('html-webpack-plugin')
6
7// add hot-reload related code to entry chunks
8Object.keys(baseConfig.entry).forEach(function (name) {
9 baseConfig.entry[name] = ['./build/dev-client'].concat(baseConfig.entry[name])
10})
11
12// 把examples下所有index.html转换成测试例子.html
13fs.readdirSync('./examples').forEach((file) => {
14 baseConfig.plugins.push(
15 // https://github.com/ampedandwired/html-webpack-plugin
16 new HtmlWebpackPlugin({
17 filename: file + '.html',
18 template: `examples/${file}/index.html`,
19 inject: false
20 })
21 )
22})
23
24// 把examples下子目录里的main.js打包成对应组件名的App.js
25fs.readdirSync('./examples').forEach((file) => {
26 baseConfig.entry[file + 'App'] = `./examples/${file}/main.js`
27})
28
29module.exports = merge(baseConfig, {
30 // eval-source-map is faster for development
31 devtool: '#eval-source-map',
32 output: {
33 // necessary for the html plugin to work properly
34 // when serving the html from in-memory
35 publicPath: '/'
36 },
37 plugins: [
38 // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
39 new webpack.optimize.OccurenceOrderPlugin(),
40 new webpack.HotModuleReplacementPlugin(),
41 new webpack.NoErrorsPlugin(),
42 // https://github.com/ampedandwired/html-webpack-plugin
43 new HtmlWebpackPlugin({
44 filename: 'index.html',
45 template: 'index.html',
46 inject: true
47 })
48 ]
49})