|
| 1 | +# Getting Started |
| 2 | + |
| 3 | +## Bundler integrations |
| 4 | + |
| 5 | +### Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm i -D unplugin-vue-macros |
| 9 | + |
| 10 | +# or yarn |
| 11 | +yarn add -D unplugin-vue-macros |
| 12 | + |
| 13 | +# or pnpm |
| 14 | +pnpm add -D unplugin-vue-macros |
| 15 | +``` |
| 16 | + |
| 17 | +#### Vite (first-class support) |
| 18 | + |
| 19 | +```ts |
| 20 | +// vite.config.ts |
| 21 | +import VueMacros from 'unplugin-vue-macros/vite' |
| 22 | +import Vue from '@vitejs/plugin-vue' |
| 23 | +// import VueJsx from '@vitejs/plugin-vue-jsx' |
| 24 | + |
| 25 | +export default defineConfig({ |
| 26 | + plugins: [ |
| 27 | + VueMacros({ |
| 28 | + plugins: { |
| 29 | + vue: Vue(), |
| 30 | + // vueJsx: VueJsx(), // if needed |
| 31 | + }, |
| 32 | + }), |
| 33 | + ], |
| 34 | +}) |
| 35 | +``` |
| 36 | + |
| 37 | +#### Rollup (first-class support) |
| 38 | + |
| 39 | +```ts |
| 40 | +// rollup.config.js |
| 41 | +import Vue from 'unplugin-vue/rollup' |
| 42 | +import VueMacros from 'unplugin-vue-macros/rollup' |
| 43 | + |
| 44 | +export default { |
| 45 | + plugins: [ |
| 46 | + VueMacros({ |
| 47 | + plugins: { |
| 48 | + vue: Vue(), |
| 49 | + // vueJsx: VueJsx(), // if needed |
| 50 | + }, |
| 51 | + }), |
| 52 | + ], |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +#### esbuild |
| 57 | + |
| 58 | +```js |
| 59 | +// esbuild.config.js |
| 60 | +import { build } from 'esbuild' |
| 61 | + |
| 62 | +build({ |
| 63 | + plugins: [ |
| 64 | + require('unplugin-vue-macros/esbuild')({ |
| 65 | + plugins: { |
| 66 | + vue: require('unplugin-vue/esbuild')(), |
| 67 | + // vueJsx: VueJsx(), // if needed |
| 68 | + }, |
| 69 | + }), |
| 70 | + ], |
| 71 | +}) |
| 72 | +``` |
| 73 | + |
| 74 | +#### Webpack |
| 75 | + |
| 76 | +```js |
| 77 | +// webpack.config.js |
| 78 | +module.exports = { |
| 79 | + /* ... */ |
| 80 | + plugins: [ |
| 81 | + require('unplugin-vue-macros/webpack')({ |
| 82 | + plugins: { |
| 83 | + vue: require('unplugin-vue/webpack')(), |
| 84 | + // vueJsx: VueJsx(), // if needed |
| 85 | + }, |
| 86 | + }), |
| 87 | + ], |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +## TypeScript Support |
| 92 | + |
| 93 | +```json |
| 94 | +// tsconfig.json |
| 95 | +{ |
| 96 | + "compilerOptions": { |
| 97 | + // ... |
| 98 | + "types": ["unplugin-vue-macros/macros-global" /* ... */] |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +## Volar Support |
| 104 | + |
| 105 | +For detailed configuration, please refer to the description of the specific macro. |
| 106 | + |
| 107 | +```bash |
| 108 | +npm i -D @vue-macros/volar |
| 109 | +``` |
| 110 | + |
| 111 | +```json |
| 112 | +// tsconfig.json |
| 113 | +{ |
| 114 | + "vueCompilerOptions": { |
| 115 | + "plugins": [ |
| 116 | + "@vue-macros/volar/define-model", |
| 117 | + "@vue-macros/volar/short-vmodel" |
| 118 | + // ...more feature |
| 119 | + ] |
| 120 | + // ... |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +:tada: Congratulations! You have successfully set up unplugin-vue-macros. |
| 126 | + |
| 127 | +To learn more about the macros, please visit [All Macros](/macros/) :laughing:. |
0 commit comments