-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
97 lines (87 loc) · 2.13 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
var fs = require('fs');
var path = require('path');
let watch = require('watch');
var webpack = require('webpack');
var targets = [
{
entry: './index.js',
target: 'web',
node: {
fs: 'empty'
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'flux.min.js',
library: 'Flux'
},
module: {
rules: [
{
test: /\.js$/,
include: [
path.join(__dirname, 'lib')
],
use: ['babel-loader', 'eslint-loader']
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
},
{
entry: './index.js',
target: 'node',
node: {
fs: 'empty'
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'flux.js',
sourceMapFilename: 'flux.map.js',
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.js$/,
include: [
path.join(__dirname, 'lib')
],
use: ['babel-loader', 'eslint-loader']
}
]
},
plugins: [
]
}
];
watch.watchTree('lib', {
ignoreDotFiles: true,
aggregateTimeout: 300, // wait so long for more changes
poll: true // use polling instead of native watchers
}, function() {
compile();
});
function compile() {
targets.forEach(function(target) {
var config = Object.assign({}, 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;
});
});
}