-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathbuild.js
75 lines (69 loc) · 1.89 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
var fs = require("fs");
var path = require("path");
var conf = require("./config");
var webpack = require("webpack");
var merge = require("webpack-merge");
function webpackConfig(dir, additionalConfig) {
var config = conf.load();
var babelOpts = {cacheDirectory: true};
if (!fs.existsSync(path.join(process.cwd(), '.babelrc'))) {
babelOpts.presets = ["es2015"];
babelOptsplugins = [
"transform-class-properties",
"transform-object-assign",
"transform-object-rest-spread"
];
}
var webpackConfig = {
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: babelOpts
}
}
]
},
context: path.join(process.cwd(), dir),
entry: {},
target: "node",
plugins: [new webpack.IgnorePlugin(/vertx/)],
output: {
path: path.join(
process.cwd(),
config.build.functions || config.build.Functions
),
filename: "[name].js",
libraryTarget: "commonjs"
},
devtool: false
};
fs.readdirSync(path.join(process.cwd(), dir)).forEach(function(file) {
if (file.match(/\.js$/)) {
var name = file.replace(/\.js$/, "");
webpackConfig.entry[name] = "./" + name;
}
});
if (additionalConfig) {
var webpackAdditional = require(path.join(process.cwd(), additionalConfig));
return merge.smart(webpackConfig, webpackAdditional);
}
return webpackConfig;
}
exports.run = function(dir, additionalConfig) {
return new Promise(function(resolve, reject) {
webpack(webpackConfig(dir, additionalConfig), function(err, stats) {
if (err) {
return reject(err);
}
resolve(stats);
});
});
};
exports.watch = function(dir, additionalConfig, cb) {
var compiler = webpack(webpackConfig(dir));
compiler.watch(webpackConfig(dir), cb);
};