@substrate-system/debug 0.9.34 → 0.9.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,8 +31,15 @@ generated by typescript.
|
|
|
31
31
|
- [Install](#install)
|
|
32
32
|
- [Browser](#browser)
|
|
33
33
|
* [Factor out of production](#factor-out-of-production)
|
|
34
|
+
+ [Esbuild Bundler](#esbuild-bundler)
|
|
35
|
+
+ [Vite Bundler](#vite-bundler)
|
|
36
|
+
+ [Dynamic Imports](#dynamic-imports)
|
|
37
|
+
+ [Dynamic Imports](#dynamic-imports-1)
|
|
34
38
|
* [HTML `importmap`](#html-importmap)
|
|
39
|
+
+ [Development](#development)
|
|
40
|
+
+ [Production](#production)
|
|
35
41
|
* [Vite Example](#vite-example)
|
|
42
|
+
+ [Staging Environment](#staging-environment)
|
|
36
43
|
- [Cloudflare](#cloudflare)
|
|
37
44
|
- [Node JS](#node-js)
|
|
38
45
|
- [Config](#config)
|
|
@@ -81,6 +88,43 @@ debug('hello logs')
|
|
|
81
88
|
|
|
82
89
|
### Factor out of production
|
|
83
90
|
|
|
91
|
+
Two options: either dynamic imports or use your bundler to swap files.
|
|
92
|
+
|
|
93
|
+
#### Esbuild Bundler
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
esbuild src/app.js --bundle --alias:@substrate-system/debug=@substrate-system/debug/noop > ./dist/app.js
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Vite Bundler
|
|
100
|
+
|
|
101
|
+
Use the `resolve.alias` configuration. Pass a function that received `mode` as
|
|
102
|
+
an argument.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
// vite.config.js
|
|
106
|
+
import { defineConfig } from 'vite';
|
|
107
|
+
import path from 'node:path';
|
|
108
|
+
|
|
109
|
+
export default defineConfig(({ mode }) => {
|
|
110
|
+
const isProd = mode === 'production';
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
resolve: {
|
|
114
|
+
alias: {
|
|
115
|
+
// When in production, swap 'my-debug-module' for a local no-op file
|
|
116
|
+
'@substrate-system/debug': (isProd ?
|
|
117
|
+
'@substrate-system/debug/noop' :
|
|
118
|
+
'@substrate-system/debug'),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
#### Dynamic Imports
|
|
127
|
+
|
|
84
128
|
Use [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)
|
|
85
129
|
to keep this entirely out of production code, so your bundle is smaller.
|
|
86
130
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@substrate-system/debug",
|
|
3
3
|
"description": "Debug utility",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.9.
|
|
5
|
+
"version": "0.9.36",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"./dist/*"
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"exmaple:node": "npx esbuild --platform=node --bundle ./example/node.ts | DEBUG=\"hello:*\" node",
|
|
71
71
|
"build-example": "vite build",
|
|
72
72
|
"build-docs": "typedoc ./src/index.ts ./src/browser/index.ts ./node.ts ./src/cloudflare/index.ts",
|
|
73
|
-
"toc": "markdown-toc --maxdepth
|
|
73
|
+
"toc": "markdown-toc --maxdepth 4 -i README.md",
|
|
74
74
|
"start": "vite --mode=staging",
|
|
75
75
|
"start:ls": "vite --config vite-ls.config.js example-ls",
|
|
76
76
|
"preversion": "npm run lint",
|