-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathwebpack.config.js
66 lines (56 loc) · 1.45 KB
/
webpack.config.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
var path = require('path');
var webpack = require('webpack');
var targets = [
{
target: 'web',
output: {
path: __dirname + '/dist',
filename: 'modal.min.js',
libraryTarget: 'var',
library: 'Modal'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({minimize: true})
],
},
{
target: 'node',
output: {
path: __dirname + '/dist',
filename: 'modal.js',
libraryTarget: 'commonjs2'
}
}
];
var baseConfig = {
entry: './index.js',
module: {
loaders: [
{
test: /\.js$/,
include: path.join(__dirname, 'lib'),
loaders: ['babel-loader', 'eslint-loader']
}
]
}
};
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;
});
});