Browse Source

add webpack for browser compatibility

master
nitowa 1 year ago
parent
commit
3931532509
3 changed files with 5197 additions and 31 deletions
  1. 5138
    29
      package-lock.json
  2. 16
    2
      package.json
  3. 43
    0
      src/webpack.js

+ 5138
- 29
package-lock.json
File diff suppressed because it is too large
View File


+ 16
- 2
package.json View File

1
 {
1
 {
2
   "name": "xrpio",
2
   "name": "xrpio",
3
-  "version": "0.1.6",
3
+  "version": "0.1.7",
4
   "repository": {
4
   "repository": {
5
     "type": "git",
5
     "type": "git",
6
     "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
6
     "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
12
   "homepage": "https://gitea.nitowa.xyz/docs/xrpio",
12
   "homepage": "https://gitea.nitowa.xyz/docs/xrpio",
13
   "description": "XRP arbitrary data writer and reader",
13
   "description": "XRP arbitrary data writer and reader",
14
   "main": "lib/src/index.js",
14
   "main": "lib/src/index.js",
15
+  "files": [
16
+    "lib/src",
17
+    "lib/browser"
18
+  ],
15
   "scripts": {
19
   "scripts": {
16
     "clean": "rm -rf gui/main.js gui/index.html gateway/main.js build lib docs",
20
     "clean": "rm -rf gui/main.js gui/index.html gateway/main.js build lib docs",
17
     "start": "npm run build && npm run launch",
21
     "start": "npm run build && npm run launch",
18
     "launch": "node ./lib/Launcher.js",
22
     "launch": "node ./lib/Launcher.js",
19
     "tsc": "tsc",
23
     "tsc": "tsc",
20
-    "build": "npm run clean && tsc",
24
+    "build": "npm run clean && tsc && npm run webpack",
21
     "build-all": "npm run build && npm run webpack-gui",
25
     "build-all": "npm run build && npm run webpack-gui",
22
     "webpack-gui": "webpack --config webpack.gui.js --progress && cp build/gui/main.js gui",
26
     "webpack-gui": "webpack --config webpack.gui.js --progress && cp build/gui/main.js gui",
23
     "webpack-gateway": "webpack --config webpack.gateway.js --progress && cp build/gateway/main.js gateway",
27
     "webpack-gateway": "webpack --config webpack.gateway.js --progress && cp build/gateway/main.js gateway",
24
     "test": "npm run build && mocha --bail=true ./lib/test/*.js",
28
     "test": "npm run build && mocha --bail=true ./lib/test/*.js",
25
     "deploy": "node ./lib/Deploy.js",
29
     "deploy": "node ./lib/Deploy.js",
30
+    "webpack": "webpack --config ./src/webpack.js",
26
     "docs": "typedoc --out docs --readme ./README.md --plugin typedoc-plugin-markdown --hideBreadcrumbs ./src/index.ts"
31
     "docs": "typedoc --out docs --readme ./README.md --plugin typedoc-plugin-markdown --hideBreadcrumbs ./src/index.ts"
27
   },
32
   },
28
   "author": "nitowa",
33
   "author": "nitowa",
37
     "@types/node": "^14.14.37",
42
     "@types/node": "^14.14.37",
38
     "base-64": "^1.0.0",
43
     "base-64": "^1.0.0",
39
     "browserify-zlib": "^0.2.0",
44
     "browserify-zlib": "^0.2.0",
45
+    "buffer": "^6.0.3",
40
     "chai": "^4.3.4",
46
     "chai": "^4.3.4",
41
     "crypto-browserify": "^3.12.0",
47
     "crypto-browserify": "^3.12.0",
48
+    "https-browserify": "^1.0.0",
42
     "mocha": "^9.2.0",
49
     "mocha": "^9.2.0",
50
+    "net": "^1.0.2",
43
     "node-fetch": "^2.6.2",
51
     "node-fetch": "^2.6.2",
44
     "process": "^0.11.10",
52
     "process": "^0.11.10",
53
+    "stream-browserify": "^3.0.0",
54
+    "stream-http": "^3.2.0",
55
+    "tls": "^0.0.1",
45
     "ts-loader": "^8.1.0",
56
     "ts-loader": "^8.1.0",
46
     "typedoc": "^0.22.11",
57
     "typedoc": "^0.22.11",
47
     "typedoc-plugin-markdown": "^3.11.12",
58
     "typedoc-plugin-markdown": "^3.11.12",
48
     "typescript": "^4.5.0",
59
     "typescript": "^4.5.0",
60
+    "url": "^0.11.0",
49
     "utf8": "^3.0.0",
61
     "utf8": "^3.0.0",
62
+    "webpack": "^5.75.0",
63
+    "webpack-cli": "^5.0.0",
50
     "wtfnode": "^0.9.1"
64
     "wtfnode": "^0.9.1"
51
   }
65
   }
52
 }
66
 }

+ 43
- 0
src/webpack.js View File

1
+const path = require('path');
2
+const webpack = require('webpack');
3
+
4
+module.exports = {
5
+  mode: "production",
6
+  target: "web",
7
+  entry: path.resolve(__dirname, 'index.ts'),
8
+  output: {
9
+    path: path.resolve(__dirname, '..', 'lib', 'browser'),
10
+    filename: "xrpio.browser.js",
11
+    libraryTarget: "window"
12
+  },
13
+  resolve: {
14
+    extensions: [".ts", ".tsx", ".js"],
15
+    fallback: {
16
+      "https": require.resolve("https-browserify"),
17
+      "zlib": require.resolve("browserify-zlib"),
18
+      "stream": require.resolve("stream-browserify"),
19
+      "crypto": require.resolve("crypto-browserify"),
20
+      "http": require.resolve("stream-http"),
21
+      "https": require.resolve("https-browserify")
22
+    }
23
+  },
24
+  module: {
25
+    rules: [
26
+      {
27
+        test: /\.ts?$/, 
28
+        loader: "ts-loader"
29
+      },
30
+    ]
31
+  },
32
+  optimization: {
33
+    minimize: false
34
+  },
35
+  externals: {
36
+  },
37
+  plugins: [
38
+    new webpack.ProvidePlugin({
39
+      process: 'process/browser',
40
+      Buffer: ['buffer', 'Buffer']
41
+    })
42
+  ]
43
+}

Loading…
Cancel
Save