-
Notifications
You must be signed in to change notification settings - Fork 639
/
build.js
executable file
·109 lines (99 loc) · 2.63 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
101
102
103
104
105
106
107
/**
* Created by du on 16/9/24.
*/
var path = require('path');
var webpack = require('webpack');
var env=process.argv[2]||"dev"
require("shelljs/global")
//For cdn entry
var entry={
"engine-wrapper": "./src/engine-wrapper.js",
"fly": "./src/fly.js",
"adapter/dsbridge":"./src/adapter/dsbridge.js",
"adapter/webviewjsbridge":"./src/adapter/webviewjsbridge.js",
}
var output = {
path: path.resolve("./dist"),
filename: "[name].js"
}
var plugins=[];
var npmExtra = {
"wx": "./src/wx.js",
"weex": "./src/weex.js",
"hap": "./src/hap.js",
"ap": "./src/ap.js"
}
//for npm require
if(env==="npm"){
Object.assign(entry, npmExtra)
output.path=path.resolve("./dist/npm")
output.libraryTarget = "umd"
} else if (env === "dev") {
entry={
"../demon/dist/test": "./demon/test.js",
"../demon/dist/typeScriptTest": "./demon/typeScriptTest.js"
}
} else if (env === "test") {
entry = {"test": "./test/test.js"}
output = {
path: path.resolve("./test/output"),
filename: "[name].js"
}
}
else {
if(env==="cdn-min"||env==="umd"){
output.filename = "[name].min.js"
plugins.push(new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: true
// },
sourceMap: true
}))
}
if(env==="umd") {
Object.assign(entry, npmExtra)
output.libraryTarget = "umd"
output.path=path.resolve("./dist/umd")
output.filename = "[name].umd.min.js"
}
}
var config= {
entry: entry,
output: output,
//devtool: env !== "dev"? '#source-map': false,
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve('./src'), path.resolve('./test'), path.resolve('./index.js')],
use:[
{
loader: 'keep-loader',
options:{
keep:env
}
},
{
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')
});
cp("./dist/npm/wx.js", "./miniprogram_dist/index.js")
cp("./dist/npm/engine-wrapper.js", "./miniprogram_dist/engine-wrapper.js")