forked from adrai/flowchart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (81 loc) · 2.04 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var path = require('path');
var webpack = require('webpack');
var moment = require('moment');
var component = require('./package.json');
var banner =
'// ' + component.name + ', v' + component.version + '\n' +
'// Copyright (c)' + moment().format('YYYY') + ' Adriano Raiano (adrai).\n' +
'// Distributed under MIT license\n' +
'// http://adrai.github.io/flowchart.js\n';
var NODE_ENV = process.env.NODE_ENV || 'development';
var defines = new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(NODE_ENV)
}
});
var config = {
devtool: 'source-map', // always build source map
entry: [
'webpack-hot-middleware/client',
'./index'
],
output: {
path: path.join(__dirname, 'release'),
filename: component.name + '.js',
publicPath: '/release/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
defines
],
resolve: {
extensions: ['', '.js'],
modulesDirectories: ['src', 'node_modules'],
alias: {
'dev/raphael.core.js': './dev/raphael.core.js',
'raphael.core': './raphael.core.js',
'raphael.svg': './dev/raphael.svg.js',
'raphael.vml': './dev/raphael.vml.js'
}
}
};
if (NODE_ENV === 'production') {
var minified = process.env.MINIFIED == '1';
var withoutJs = component.name;
withoutJs = withoutJs.replace('.js', '');
var filename = minified ? withoutJs + '.min.js' : withoutJs + '.js';
var uglifyOptions = {
sourceMap: true,
compressor: {
warnings: false,
dead_code: true
},
output: {
preamble: banner,
comments: false
}
};
if (!minified) {
uglifyOptions.beautify = true;
uglifyOptions.mangle = false;
uglifyOptions.output.comments = 'all';
}
config.entry = './index';
config.externals = {
raphael: 'Raphael'
};
config.output = {
devtoolLineToLine: true,
sourceMapFilename: filename + '.map',
path: path.join(__dirname, 'release'),
filename: filename,
libraryTarget: 'umd'
};
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
defines,
new webpack.optimize.UglifyJsPlugin(uglifyOptions)
];
}
module.exports = config;