-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
123 lines (116 loc) · 4.52 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var webpack = require('webpack');
var path = require('path');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
var { generateManifest } = require("plugin-api/build/generateManifest");
function getConfig(isProduction) {
var isDebug = !isProduction;
var sourceRoot = path.join(__dirname, "src");
var nodeModulesPath = path.join(__dirname, "node_modules");
var outputRoot = path.join(__dirname, "dist");
var plugins = [
new ForkTsCheckerWebpackPlugin({
tsconfig: path.resolve(".", "tsconfig.json"),
tslint: path.resolve(".", isProduction ? "tslint.prod.json" : "tslint.json"),
async: false
}),
// These are preprocessor constants which are replaced inline (that's why the extra quotes)
new webpack.DefinePlugin({
// This is needed to be able to activate some features for development (like ReduxDevTools)
// and, also, some libs (like React) have an optimized (smaller&faster) builds
// if NODE_ENV is set to "production"
'process.env.NODE_ENV': JSON.stringify(isDebug ? 'development' : 'production'),
'__plugin_manifest__': JSON.stringify(generateManifest(require("./package.json")))
})
];
if (!isDebug) {
plugins.push(new webpack.HashedModuleIdsPlugin());
}
return {
mode: isDebug ? "development" : "production",
context: sourceRoot,
entry: './plugin',
output: {
path: outputRoot,
sourcePrefix: '',
crossOriginLoading: "anonymous",
filename: "index.js",
chunkFilename: "[contentHash].bundle.js",
pathinfo: !!isDebug,
library: "__aleth_io__ethIbft2",
libraryTarget: "jsonp"
},
optimization: isDebug ? void 0 : {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
// Don't merge statements with comma. This makes breakpoints unusable in debugger.
compress: {
sequences: false,
join_vars: false,
// Dropping unused variables causes problems with libraries such as MobX
unused: false,
warnings: false,
// FIX https://github.com/mishoo/UglifyJS2/issues/1317
if_return: false,
// FIX https://github.com/mishoo/UglifyJS2/issues/2498
properties: false
},
mangle: {
safari10: true
}
},
sourceMap: true
})
]
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /rlp/,
enforce: "pre",
loader: "source-map-loader"
},
{
test: /\.tsx?$/,
loader: 'ts-loader?configFile=tsconfig.json',
options: {
transpileOnly: true
}
}
]
},
resolve: {
modules: [
sourceRoot,
nodeModulesPath
],
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
externals: [
{ "react": "commonjs react" },
{ "react-dom": "commonjs react-dom" },
{ "mobx": "commonjs mobx" },
{ "mobx-react": "commonjs mobx-react" },
{ "styled-components": "commonjs styled-components" },
function(context, request, callback) {
if (/^plugin-api\/.+$/.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
},
],
// If incremental build performance becomes an issue, this option can be enabled
// to generate faster source maps
devtool: /*isDebug ? 'eval-source-map' : */'source-map',
// Uncomment this to use polling instead of file watchers (e.g. too few available
// from environment)
watchOptions: {
aggregateTimeout: 0
//poll: true
},
plugins: plugins
};
}
module.exports = getConfig;