forked from KaneCohen/tokenfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
94 lines (81 loc) · 2.04 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
var fs = require('fs');
var path = require('path');
var sass = require('node-sass');
var webpack = require('webpack');
var targets = [
{
target: 'web',
output: {
path: __dirname + '/dist',
filename: 'tokenfield.min.js',
library: 'Tokenfield'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
},
{
target: 'node',
output: {
path: __dirname + '/dist',
filename: 'tokenfield.js',
libraryTarget: 'commonjs2'
}
}
];
var baseConfig = {
debug: false,
entry: './lib/tokenfield',
module: {
loaders: [
{
test: /\.js$/,
include: path.join(__dirname, 'lib'),
loaders: ['babel', 'eslint']
}
]
}
};
sass.render({
sourceMap: true,
file: 'lib/scss/tokenfield.scss',
outFile: __dirname + '/dist/tokenfield.css'
}, function(err, result) {
if (err) {
console.log(err);
return 1;
}
fs.writeFile(__dirname + '/dist/tokenfield.css', result.css, function(err) {
if (err) {
console.log(err);
return 1;
}
fs.writeFile(__dirname + '/dist/tokenfield.css.map', result.map, function(err) {
if (err) {
console.log(err);
return 1;
}
console.log('SASS compiled to CSS');
});
});
});
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;
});
});