Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 3b29ceb

Browse files
authored
Merge pull request #4728 from trufflesuite/biffy-to-wacker
Migrate contract to use webpack from browserify
2 parents d63ae98 + 2a83975 commit 3b29ceb

File tree

5 files changed

+89
-371
lines changed

5 files changed

+89
-371
lines changed

packages/contract/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
22
yarn.lock
33
package-lock.json
4-
dist
4+
browser-dist

packages/contract/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,3 @@ const contract = (json = {}) => {
1313
contract.version = truffleContractVersion;
1414

1515
module.exports = contract;
16-
17-
if (typeof window !== "undefined") {
18-
window.TruffleContract = contract;
19-
}

packages/contract/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"main": "index.js",
1717
"scripts": {
1818
"build": "yarn compile",
19-
"compile": "sh -c \"mkdir -p ./dist\" && browserify --debug ./index.js | exorcist ./dist/truffle-contract.js.map > ./dist/truffle-contract.js && uglifyjs ./dist/truffle-contract.js -o ./dist/truffle-contract.min.js",
19+
"compile": "NODE_ENV=production webpack --config ./webpack.config.js && NODE_ENV=development webpack --config ./webpack.config.js",
2020
"prepare": "yarn compile",
2121
"publish:next": "node ../truffle/scripts/prereleaseVersion.js next next"
2222
},
@@ -37,9 +37,14 @@
3737
"web3-utils": "1.7.4"
3838
},
3939
"devDependencies": {
40-
"browserify": "^17.0.0",
41-
"exorcist": "^2.0.0",
42-
"uglify-es": "^3.3.9"
40+
"buffer": "6.0.3",
41+
"crypto-browserify": "^3.12.0",
42+
"os-browserify": "^0.3.0",
43+
"path-browserify": "^1.0.1",
44+
"stream-browserify": "^3.0.0",
45+
"vm-browserify": "^1.1.2",
46+
"webpack": "^5.73.0",
47+
"webpack-cli": "^4.10.0"
4348
},
4449
"keywords": [
4550
"abstraction",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const path = require("path");
2+
const webpack = require("webpack");
3+
4+
//TODO: there's probably a better way to do this where webpack is called once
5+
//and it will generate both production and development packs
6+
const suffix = process.env.NODE_ENV === "production" ? ".min" : "";
7+
const entryName = `truffle-contract${suffix}`;
8+
9+
module.exports = {
10+
context: path.resolve(__dirname),
11+
entry: {
12+
[entryName]: "./index.js"
13+
},
14+
output: {
15+
filename: "[name].js",
16+
path: path.resolve(__dirname, "browser-dist"),
17+
library: {
18+
name: "TruffleContract",
19+
type: "global"
20+
}
21+
},
22+
devtool: "source-map",
23+
plugins: [
24+
new webpack.ProvidePlugin({
25+
Buffer: ["buffer", "Buffer"]
26+
}),
27+
new webpack.ProvidePlugin({
28+
process: "process/browser"
29+
}),
30+
],
31+
resolve: {
32+
fallback: {
33+
crypto: require.resolve("crypto-browserify"),
34+
http: require.resolve("stream-http"),
35+
https: require.resolve("https-browserify"),
36+
os: require.resolve("os-browserify/browser"),
37+
path: require.resolve("path-browserify"),
38+
stream: require.resolve("stream-browserify"),
39+
vm: require.resolve("vm-browserify")
40+
}
41+
}
42+
};

0 commit comments

Comments
 (0)