forked from wendux/ajax-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·103 lines (92 loc) · 2.3 KB
/
build.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
/**
* Created by du on 16/9/24.
*/
let path = require('path');
let webpack = require('webpack');
let env = process.argv[2] || "dev"
console.log(env)
let entry = {
"ajaxhook": "./index.js",
}
let plugins = [];
var output={
path: path.resolve("./dist/")
}
if (env === "test") {
entry = {
"es": "./test/es.js",
'hook': './test/hook.js',
'proxy': './test/proxy.js'
}
output = {
path: path.resolve("./test/dist"),
filename: "[name].js"
}
} else if (env === "cdn") {
entry = {
"ajaxhook": "./src/cdn.js",
"ajaxhook.core": "./src/cdn-core.js",
}
output.filename = "[name].js"
output.libraryTarget = 'window'
} else if (env === "cdn-min") {
entry = {
"ajaxhook": "./src/cdn.js",
"ajaxhook.core": "./src/cdn-core.js",
// "ajaxhook": "./src/xhr-proxy.js",
// "ajaxhook.core": "./src/xhr-hook.js",
}
output.filename = "[name].min.js"
output.libraryTarget = 'window'
plugins.push(new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: true
// },
sourceMap: true
}))
}
else if (env === "umd") {
output.libraryTarget = "umd"
output.filename = "[name].umd.js"
}else if (env === "umd-min") {
output.libraryTarget = "umd"
output.filename = "[name].umd.min.js"
plugins.push(new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: true
// },
sourceMap: true
}))
}
let config = {
devtool: env.endsWith('min')?'source-map':'none',
entry: entry,
output: output,
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve('./src'), path.resolve('./test'), path.resolve('./index.js')],
use: [
{
loader: "babel-loader",
options: {
presets: ['es2015']
}
},
]
}
]
},
plugins: plugins
}
webpack(config, function (err, stats) {
if (err) throw err;
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
});