@furryr/typescript-runtime 1.0.0
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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/typescript-runtime.global.js +53 -0
- package/dist/typescript-runtime.global.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License Copyright (c) 2026 furryr
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of
|
|
4
|
+
charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# typescript-runtime
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README_zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Run small TypeScript and TSX scripts directly in the browser.
|
|
6
|
+
|
|
7
|
+
`typescript-runtime` is useful for demos, examples, prototypes, and local experiments. It transforms TypeScript in the browser and injects normal JavaScript scripts back into the page.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Load `typescript-runtime` before your TypeScript scripts:
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="./dist/typescript-runtime.global.js"></script>
|
|
15
|
+
|
|
16
|
+
<script type="text/typescript">
|
|
17
|
+
const message: string = 'Hello from TypeScript';
|
|
18
|
+
document.body.append(message);
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
External files work too:
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script src="./dist/typescript-runtime.global.js"></script>
|
|
26
|
+
<script type="text/typescript" src="./app.ts"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Supported script markers:
|
|
30
|
+
|
|
31
|
+
- `type="text/typescript"`
|
|
32
|
+
- `type="application/typescript"`
|
|
33
|
+
- `type="text/ts"`
|
|
34
|
+
- `type="application/ts"`
|
|
35
|
+
- `type="text/typescript-tsx"`
|
|
36
|
+
- `type="application/typescript-tsx"`
|
|
37
|
+
- `src` ending in `.ts`, `.mts`, `.cts`, `.tsx`, `.mtsx`, or `.ctsx`
|
|
38
|
+
|
|
39
|
+
External scripts are loaded with `fetch`, so normal browser CORS rules apply.
|
|
40
|
+
|
|
41
|
+
## Imports
|
|
42
|
+
|
|
43
|
+
Relative imports between TypeScript files are supported:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { greet } from './greet.ts';
|
|
47
|
+
|
|
48
|
+
greet('world');
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Dynamic imports are also supported:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const mod = await import('./greet.ts');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
Add a `<tsconfig>` element before your TypeScript scripts:
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<tsconfig src="./tsconfig.browser.json"></tsconfig>
|
|
63
|
+
<script src="./dist/typescript-runtime.global.js"></script>
|
|
64
|
+
<script type="text/typescript" src="./app.ts"></script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"compilerOptions": {
|
|
72
|
+
"sourceMap": true
|
|
73
|
+
},
|
|
74
|
+
"scriptType": "module"
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Defaults:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"compilerOptions": {
|
|
83
|
+
"sourceMap": true
|
|
84
|
+
},
|
|
85
|
+
"scriptType": "module"
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## TSX / JSX
|
|
90
|
+
|
|
91
|
+
TSX/JSX is disabled unless you provide explicit JSX runtime settings.
|
|
92
|
+
|
|
93
|
+
Classic JSX example:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"compilerOptions": {
|
|
98
|
+
"jsx": "react",
|
|
99
|
+
"jsxFactory": "__ts.jsx",
|
|
100
|
+
"jsxFragmentFactory": "__ts.Fragment"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Then use `type="text/typescript-tsx"` or a `.tsx` file:
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<script type="text/typescript-tsx">
|
|
109
|
+
const el = <div>Hello JSX</div>;
|
|
110
|
+
</script>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`typescript-runtime` does not provide a JSX runtime. You must provide `__ts.jsx`, React, or another runtime yourself.
|
|
114
|
+
|
|
115
|
+
## Source Maps
|
|
116
|
+
|
|
117
|
+
When `compilerOptions.sourceMap` is enabled, transformed scripts include an inline `data:` source map.
|
|
118
|
+
|
|
119
|
+
External files map back to their original import paths, such as `/example/greet.ts`. Inline scripts appear as virtual files like `ts://inline/1.ts`.
|
|
120
|
+
|
|
121
|
+
## Example
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
pnpm install
|
|
125
|
+
pnpm build
|
|
126
|
+
pnpm example
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Open `http://127.0.0.1:8080/example/`.
|
|
130
|
+
|
|
131
|
+
## Notes
|
|
132
|
+
|
|
133
|
+
`typescript-runtime` is not a production bundler. It is intended for development, demos, and lightweight browser experiments.
|