-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
72 lines (62 loc) · 1.57 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
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var targets = [
{
target: 'web',
output: {
path: __dirname + '/dist',
filename: 'cronus.min.js',
library: 'Cronus'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({minimize: true}),
new webpack.IgnorePlugin(/^\.\/lang$/)
]
},
{
target: 'node',
output: {
path: __dirname + '/dist',
filename: 'cronus.js',
libraryTarget: 'commonjs2'
},
plugins: [
new webpack.IgnorePlugin(/^\.\/lang$/)
]
}
];
var baseConfig = {
debug: false,
entry: './lib/cronus',
module: {
noParse: [/cronus/],
loaders: [
{
test: /\.js$/,
include: path.join(__dirname, 'lib'),
loaders: []
}
]
}
};
targets.forEach(function(target) {
var config = Object.assign({}, baseConfig, target);
webpack(config).run(function(err, stats) {
console.log('Generating minified bundle for production use via Webpack...');
if (err) {
console.log(err);
return 1;
}
var jsonStats = stats.toJson();
if (jsonStats.hasErrors) return jsonStats.errors.map(function(error) { return console.log(error); });
if (jsonStats.hasWarnings) {
console.log('Webpack generated the following warnings: ');
jsonStats.warnings.map(function(warning) { return console.log(warning); });
}
console.log('Webpack stats: ' + stats.toString());
//if we got this far, the build succeeded.
console.log('Package has been compiled into /dist.');
return 0;
});
});