-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
91 lines (85 loc) · 1.97 KB
/
webpack.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
/**
* bundle 使用webpack 打包
* 配置文件
* by tommyshao
*/
var path = require('path')
var fs = require('fs')
var NODE_ENV = process.env.NODE_ENV
var entryFiles = [];
function getEntries(folder) {
var paths = path.resolve(folder)
var dirs = fs.readdirSync(paths)
var matchs = [], files = {}
dirs.forEach(function(file) {
matchs = file.match(/(.+)\.js$/)
// 不包含brickplus
if(matchs && matchs[1] && matchs[1] !== 'brickPlus') {
files[matchs[1]] = path.resolve(folder, file)
}
})
return files;
}
module.exports = function(entries, output) {
/*if(/\.js$/g.test(entries)) { // 单个文件
entryFiles.push(entries)
} else { // 多文件
entryFiles = getEntries(entries)
}*/
if(typeof entries === 'string') { // 多文件
entryFiles = getEntries(entries)
} else { // 单个文件
entryFiles = entries
}
//console.log(entryFiles)
// 返回webpack.config
return {
watch: !(NODE_ENV === 'production'),
debug: !(NODE_ENV === 'production'),
profile: true,
cache: true,
//context: path.resolve(__dirname),
// entry: entryFiles,
entry: {
'Notify': './src/Notify.js'
},
output: {
path: path.join(__dirname, './static/js/brickplus'),
filename: '[name].js',
library: '[name]',
libraryTarget: 'umd'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
query: {
presets: ['es2015'],
cacheDirectory: true
},
exclude: /node_modules/
}
]
},
resolve: {
alias: {
jquery: 'bower_components/jquery/dist/jquery.min.js',
zeroPad: './src/Util/zeroPad.js'
},
extensions: ['', '.js'],
root: [path.resolve('./src')]
},
externals: [
{
jquery: {
root: 'jQuery',
commonjs2: 'jquery',
commonjs: 'jquery',
amd: 'jquery'
}
//jquery: true
}
]
}
}