0.7.1 • Published 9 months ago

unplugin-jsx-string v0.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

unplugin-jsx-string npm

Unit Test

Converts JSX to HTML strings at compile time.

Installation

npm i unplugin-jsx-string
// vite.config.ts
import JsxString from 'unplugin-jsx-string/vite'

export default defineConfig({
  plugins: [JsxString()],
})

// rollup.config.js
import JsxString from 'unplugin-jsx-string/rollup'

export default {
  plugins: [JsxString()],
}

// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [require('unplugin-jsx-string/esbuild')()],
})

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [require('unplugin-jsx-string/webpack')()],
}

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [require('unplugin-jsx-string/webpack')()],
  },
}

TypeScript Support

// tsconfig.json
{
  "compilerOptions": {
    // ...
    "types": ["unplugin-jsx-string" /* ... */]
  }
}

Usage

// basic usage
jsxToString(<div>Hello</div>)
// "<div>Hello</div>"

// class list
jsxToString(<div className={['bar', 'foo']} />)
// `<div class="bar foo"/>`

// styles
jsxToString(<div style={{ color: 'red', textAlign: 'center' }} />)
// `<div style="color:red;text-align:center"/>`

// events
jsxToString(<button onClick={() => 'clicked'}></button>)
// "<button onclick="&apos;clicked&apos;"></button>"

// children
jsxToString(
  <div>
    <p>foo</p>
    <p>bar</p>
    <br />
    <div />
    123
  </div>
)
// "<div><p>foo</p><p>bar</p><br/><div/>123</div>"

Benchmark

<div>Hello World</div> x 89,429 ops/sec ±0.88% (95 runs sampled)
<div><img src={'foo'} /><div></div></div> x 62,522 ops/sec ±0.62% (93 runs sampled)

More samples are welcome.

Sponsors

License

MIT License © 2022-PRESENT 三咲智子

0.7.1

9 months ago

0.7.0

10 months ago

0.6.0

1 year ago

0.5.6

1 year ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.3-0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago