This repository has been archived by the owner on Jul 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
webpack.example.config.js
109 lines (88 loc) · 2.33 KB
/
webpack.example.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* @Author: dmyang
* @Date: 2015-11-10 10:42:22
* @Last Modified by: dmyang
* @Last Modified time: 2016-04-07 16:51:15
*/
'use strict';
const path = require('path')
const fs = require('fs')
const webpack = require('webpack')
const glob = require('glob')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const debug = global.debug || process.env.NODE_ENV === 'develoption'
const src = './examples/'
const assets = './examples/assets'
const publicPath = ''
let genEntries = () => {
let entryFiles = glob.sync(src + '/*.{js,jsx}')
let map = {}
entryFiles.forEach((filePath) => {
let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
map[filename] = filePath
})
return map
}
let entries = genEntries()
let getPlugins = () => {
let entryHtml = glob.sync(src + '/*.html')
let r = []
entryHtml.forEach((filePath) => {
let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
let conf = {
template: filePath,
filename: filename + '.html'
}
if(filename in entries) {
conf.inject = 'body'
conf.chunks = ['common', filename]
}
r.push(new HtmlWebpackPlugin(conf))
})
return r
}
let config = {
entry: entries,
output: {
path: path.resolve(assets),
filename: debug ? '[name].js' : 'js/[chunkhash:8].[name].min.js',
publicPath: publicPath
},
resolve: {
root: __dirname,
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel?presets[]=es2015'
},
{
test: /\.less$/,
loader: 'style!css!less'
},
{
test: /\.css$/,
loader: 'style!css'
},
{
test: /\.(png|jpg)$/,
loader: 'url?limit=8192&name=img/'
}
]
},
plugins: getPlugins(),
devServer: {
hot: true,
noInfo: false,
inline: true,
publicPath: publicPath,
stats: {
cached: false,
colors: true
}
}
}
module.exports = config