forked from trufflesuite/truffle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.webpack.config.js
93 lines (84 loc) · 2.97 KB
/
cli.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
var path = require("path");
var fs = require("fs");
var OS = require("os");
var prependFile = require('prepend-file');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var webpack = require('webpack');
var pkg = require("./package.json");
var outputDir = path.join(__dirname, "build");
var outputFilename = 'cli.bundled.js';
module.exports = {
entry: {
cli: path.join(__dirname, "node_modules", "truffle-core", "cli.js"),
chain: path.join(__dirname, "node_modules", "truffle-core", "chain.js")
},
target: 'node',
node: {
// For this option, see here: https://github.com/webpack/webpack/issues/1599
__dirname: false,
__filename: false
},
output: {
path: outputDir,
filename: '[name].bundled.js'
},
devtool: 'source-map',
module: {
rules: [
{ test: /\.js$/, use: "shebang-loader" }
]
},
externals: [
// If you look at webpack's docs, `externals` doesn't need to be a function.
// But I never got it to work otherwise, so this is a function because "it works".
function(context, request, callback) {
// 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.
if (/^original-require$/.test(request)) {
return callback(null, 'commonjs original-require');
}
// We want to leave solc as an eternal dependency as well (for now)
if (/^solc$/.test(request)) {
return callback(null, 'commonjs solc');
}
// Mocha doesn't seem to bundle well either. This is a stop-gap until
// I can look into it further.
if (/^mocha$/.test(request)) {
return callback(null, 'commonjs mocha');
}
callback();
}
],
plugins: [
new webpack.DefinePlugin({
"BUNDLE_VERSION": JSON.stringify(pkg.version),
"BUNDLE_CHAIN_FILENAME": JSON.stringify("chain.bundled.js")
}),
// Put the shebang back on.
new webpack.BannerPlugin({banner: '#!/usr/bin/env node\n', raw: true}),
// `truffle test`
new CopyWebpackPlugin([
{ from: path.join(__dirname, "node_modules", "truffle-core", "lib", "testing", "Assert.sol") },
{ from: path.join(__dirname, "node_modules", "truffle-core", "lib", "testing", "SafeSend.sol") },
{
from: path.join(__dirname, "node_modules", "truffle-core", "lib", "templates/"),
to: "templates",
flatten: true
},
]),
new CleanWebpackPlugin(["build"]),
],
resolve: {
alias: {
// fsevents is used by chokidar and is an optional requirement
// It doesn't pack well, and is OS X specific, so let's get rid of it.
"fsevents": path.join(__dirname, "./nil.js"),
"ws": path.join(__dirname, "./nil.js"),
"original-fs": path.join(__dirname, "./nil.js"),
"scrypt": "js-scrypt",
"secp256k1": path.join(__dirname, "node_modules", "secp256k1", "elliptic.js")
}
}
}