Просмотр исходного кода

add webpack for browser compatibility

master
nitowa 2 лет назад
Родитель
Сommit
3931532509
3 измененных файлов: 5197 добавлений и 31 удалений
  1. 5138
    29
      package-lock.json
  2. 16
    2
      package.json
  3. 43
    0
      src/webpack.js

+ 5138
- 29
package-lock.json
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 16
- 2
package.json Просмотреть файл

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

+ 43
- 0
src/webpack.js Просмотреть файл

@@ -0,0 +1,43 @@
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
+}

Загрузка…
Отмена
Сохранить