-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
250 lines (235 loc) · 6.61 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const webpack = require("webpack");
const pkg = require("./package.json");
const rootDir = path.join(__dirname, "../..");
const outputDir = path.join(__dirname, "build");
const truffleLibraryDirectory = path.join(
__dirname,
"../..",
"node_modules",
"@truffle/resolver",
"solidity"
);
module.exports = {
mode: "production",
entry: {
cli: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"cli.js"
),
chain: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/environment",
"chain.js"
),
analytics: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"lib",
"services",
"analytics",
"main.js"
),
library: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"index.js"
),
consoleChild: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"lib",
"console-child.js"
),
commands: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"lib",
"commands/index.js"
)
},
target: "node",
node: {
// For this option, see here: https://github.com/webpack/webpack/issues/1599
__dirname: false,
__filename: false
},
context: rootDir,
output: {
path: outputDir,
filename: "[name].bundled.js",
libraryTarget: "commonjs",
chunkLoading: "require"
},
// There are many source map options we can choose. Choosing an option with
// "nosources" allows us to reduce the size of the bundle while still allowing
// high quality source maps.
devtool: "nosources-source-map",
optimization: {
minimize: false,
splitChunks: {
// The following two items splits the bundle into pieces ("chunks"),
// where each chunk is less than 5 million bytes (shorthand for roughly
// 5 megabytes). The first option, `chunks: all`, is the main powerhouse:
// it'll look at common chunks (pieces of code) between each entry point
// and separates them its own bundle. When an entry point is run,
// the necessary chunks will be automatically required as needed.
// This significantly speeds up bundle runtime because a) chunks can be
// cached by node (e.g., within the `require` infrastructure) and b) we
// won't `require` any chunks not needed by the command run by the user.
// It also reduces the total bundle size since chunks can be shared
// between entry points.
chunks: "all",
// I chose 5000000 based on anecdotal results on my machine. Limiting
// the size to 5000000 bytes shaved off a few hundreths of a milisecond.
// The negative here is creates more chunks. We can likely remove it and
// let webpack decide with `chunks: all` if we prefer.
maxSize: 5000000
}
},
module: {
rules: [
// ignores "#!/bin..." lines inside files
{
test: /\.js$/,
include: [
path.resolve(__dirname, "../core"),
path.resolve(__dirname, "../environment")
],
use: "shebang-loader"
}
]
},
externals: [
// truffle-config uses the original-require module.
// Here, we leave it as an external, and use the original-require
// module that's a dependency of Truffle instead.
/^original-require$/,
/^mocha$/,
/^@truffle\/debugger/, //no longer part of the bundle to keep size down
/^@truffle\/db/,
// this is the commands portion shared by cli.js and console-child.js
/^\.\/commands.bundled.js$/
],
resolve: {
alias: {
"ws": path.join(__dirname, "./nil.js"),
"bn.js": path.join(
__dirname,
"../..",
"node_modules",
"bn.js",
"lib",
"bn.js"
),
"original-fs": path.join(__dirname, "./nil.js"),
"scrypt": "js-scrypt"
}
},
stats: {
warnings: false
},
plugins: [
new webpack.DefinePlugin({
BUNDLE_VERSION: JSON.stringify(pkg.version),
BUNDLE_CHAIN_FILENAME: JSON.stringify("chain.bundled.js"),
BUNDLE_ANALYTICS_FILENAME: JSON.stringify("analytics.bundled.js"),
BUNDLE_LIBRARY_FILENAME: JSON.stringify("library.bundled.js"),
BUNDLE_CONSOLE_CHILD_FILENAME: JSON.stringify("consoleChild.bundled.js")
}),
// Put the shebang back on.
new webpack.BannerPlugin({ banner: "#!/usr/bin/env node\n", raw: true }),
new webpack.ProgressPlugin(),
// `truffle test`
new CopyWebpackPlugin({
patterns: [
{
from: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"lib",
"commands",
"init",
"initSource"
),
to: "initSource"
},
{
from: path.join(truffleLibraryDirectory, "Assert.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertAddress.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertAddressArray.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertBalance.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertBool.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertBytes32.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertBytes32Array.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertGeneral.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertInt.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertIntArray.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertString.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertUint.sol")
},
{
from: path.join(truffleLibraryDirectory, "AssertUintArray.sol")
},
{
from: path.join(truffleLibraryDirectory, "SafeSend.sol")
},
{
from: path.join(
__dirname,
"../..",
"node_modules",
"@truffle/core",
"lib",
"commands",
"create",
"templates/"
),
to: "templates"
}
]
}),
new CleanWebpackPlugin(),
// Make web3 1.0 packable
new webpack.IgnorePlugin({ resourceRegExp: /^electron$/ })
]
};