Skip to content

Commit 35272a0

Browse files
committed
feat: finish
1 parent e2f87bd commit 35272a0

File tree

16 files changed

+708
-247
lines changed

16 files changed

+708
-247
lines changed

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,116 @@
22

33
[![Unit Test](https://github.com/sxzz/unplugin-jsx-string/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/unplugin-jsx-string/actions/workflows/unit-test.yml)
44

5-
## Install
5+
## Installation
66

77
```bash
88
npm i unplugin-jsx-string
99
```
1010

11+
<details>
12+
<summary>Vite</summary><br>
13+
14+
```ts
15+
// vite.config.ts
16+
import DefineOptions from 'unplugin-jsx-string/vite'
17+
import Vue from '@vitejs/plugin-vue'
18+
19+
export default defineConfig({
20+
plugins: [Vue(), DefineOptions()],
21+
})
22+
```
23+
24+
<br></details>
25+
26+
<details>
27+
<summary>Rollup</summary><br>
28+
29+
```ts
30+
// rollup.config.js
31+
import DefineOptions from 'unplugin-jsx-string/rollup'
32+
33+
export default {
34+
plugins: [DefineOptions()], // Must be before Vue plugin!
35+
}
36+
```
37+
38+
<br></details>
39+
40+
<details>
41+
<summary>esbuild</summary><br>
42+
43+
```ts
44+
// esbuild.config.js
45+
import { build } from 'esbuild'
46+
47+
build({
48+
plugins: [
49+
require('unplugin-jsx-string/esbuild')(), // Must be before Vue plugin!
50+
],
51+
})
52+
```
53+
54+
<br></details>
55+
56+
<details>
57+
<summary>Webpack</summary><br>
58+
59+
```ts
60+
// webpack.config.js
61+
module.exports = {
62+
/* ... */
63+
plugins: [require('unplugin-jsx-string/webpack')()],
64+
}
65+
```
66+
67+
<br></details>
68+
69+
<details>
70+
<summary>Vue CLI</summary><br>
71+
72+
```ts
73+
// vue.config.js
74+
module.exports = {
75+
configureWebpack: {
76+
plugins: [require('unplugin-jsx-string/webpack')()],
77+
},
78+
}
79+
```
80+
81+
<br></details>
82+
83+
## Usage
84+
85+
```tsx
86+
// basic usage
87+
jsxToString(<div>Hello</div>)
88+
// "<div>Hello</div>"
89+
90+
// class list
91+
jsxToString(<div className={['bar', 'foo']} />)
92+
// `<div class="bar foo"/>`
93+
94+
// styles
95+
jsxToString(<div style={{ color: 'red', textAlign: 'center' }} />)
96+
// `<div style="color:red;text-align:center"/>`
97+
98+
// events
99+
jsxToString(<button onClick={() => 'clicked'}></button>)
100+
// "<button onclick="&apos;clicked&apos;"></button>"
101+
102+
// children
103+
jsxToString(
104+
<div>
105+
<p>foo</p>
106+
<p>bar</p>
107+
<br />
108+
<div />
109+
123
110+
</div>
111+
)
112+
// "<div><p>foo</p><p>bar</p><br/><div/>123</div>"
113+
```
114+
11115
## Sponsors
12116

13117
<p align="center">

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@
2929
"@babel/parser": "^7.18.4",
3030
"@babel/traverse": "^7.18.2",
3131
"@babel/types": "^7.18.4",
32+
"@rollup/pluginutils": "^4.2.1",
3233
"entities": "^4.3.0",
3334
"json5": "^2.2.1",
34-
"lodash": "^4.17.21"
35+
"lodash": "^4.17.21",
36+
"magic-string": "^0.26.2",
37+
"unplugin": "^0.7.0"
3538
},
3639
"devDependencies": {
3740
"@sxzz/eslint-config-prettier": "^2.2.2",
3841
"@sxzz/eslint-config-ts": "^2.2.2",
3942
"@types/babel__traverse": "^7.17.1",
4043
"@types/lodash": "^4.14.182",
4144
"@types/node": "*",
45+
"@types/react": "^18.0.12",
4246
"bumpp": "^7.1.1",
4347
"eslint": "^8.17.0",
4448
"eslint-define-config": "^1.5.0",

0 commit comments

Comments
 (0)