-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
80 lines (74 loc) · 1.76 KB
/
webpack.config.js
File metadata and controls
80 lines (74 loc) · 1.76 KB
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
'use strict'; // eslint-disable-line
const path = require('path');
const webpack = require('webpack');
const component = require('./package.json');
const year = (new Date()).getFullYear();
const banner = `// ${component.name} v${component.version}
// Copyright (c) ${year} GrapeCity, Inc.
// Distributed under MIT license
// http://github.com/activereports/ars-client
`;
const NODE_ENV = process.env.NODE_ENV || 'development';
const defines = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV),
},
});
const config = {
devtool: 'source-map', // always build source map
entry: './src/index',
output: {
path: path.join(__dirname, 'build'),
filename: `${component.name}.js`,
publicPath: '/build/',
},
plugins: [
new webpack.NoErrorsPlugin(),
defines,
],
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
},
],
},
};
if (NODE_ENV === 'production') {
const minified = process.env.MINIFIED === '1';
let withoutJs = component.name;
withoutJs = withoutJs.replace('.js', '');
const filename = minified ? `${withoutJs}.min.js` : `${withoutJs}.js`;
const 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 = './src/index';
config.output = {
devtoolLineToLine: true,
sourceMapFilename: `${filename}.map`,
path: path.join(__dirname, 'dist'),
filename,
libraryTarget: 'umd',
};
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
defines,
new webpack.optimize.UglifyJsPlugin(uglifyOptions),
];
}
module.exports = config;