|
1 | 1 | # unplugin-vue-source
|
2 |
| -Add a __source prop to all Elements |
| 2 | + |
| 3 | +Add a \_\_source prop to all Elements. |
| 4 | + |
| 5 | +- 🌈 Supports `Vue2` and `Vue3`. |
| 6 | +- 🪐 Support add to `<Component/>`. |
| 7 | +- ✨ JSX support in `.vue`, `.jsx`, `.tsx`. |
| 8 | +- 😃 Supports `Vite`, `Webpack`, `Rspack`, `Vue CLI`, `Rollup`, `esbuild`. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +sfc without |
| 13 | + |
| 14 | +```html |
| 15 | +<!-- /src/App.vue --> |
| 16 | +<template> |
| 17 | + <div>hello word</div> |
| 18 | +</template> |
| 19 | +``` |
| 20 | + |
| 21 | +with |
| 22 | + |
| 23 | +```html |
| 24 | +<!-- /src/App.vue --> |
| 25 | +<template> |
| 26 | + <div __source="/src/App.vue:3:3">hello word</div> |
| 27 | +</template> |
| 28 | +``` |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +jsx without |
| 33 | + |
| 34 | +```tsx |
| 35 | +// /src/App.vue |
| 36 | +export default App() { |
| 37 | + return <div>hello word</div> |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +with |
| 42 | + |
| 43 | +```tsx |
| 44 | +// /src/App.vue |
| 45 | +export default App() { |
| 46 | + return <div __source="/src/App.vue:3:9">hello word</div> |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +## Install |
| 51 | + |
| 52 | +```bash |
| 53 | +npm i -D unplugin-vue-source |
| 54 | +``` |
| 55 | + |
| 56 | +## Vue2 |
| 57 | + |
| 58 | +```ts |
| 59 | +// main.ts |
| 60 | +import Vue from 'vue'; |
| 61 | +import VueSource from "unplugin-vue-source/vue"; |
| 62 | +import App from "./App.vue"; |
| 63 | + |
| 64 | +Vue.use(VueSource); |
| 65 | + |
| 66 | +new Vue({ |
| 67 | + el: "#app", |
| 68 | + render: (h) => h(App), |
| 69 | +}); |
| 70 | +``` |
| 71 | + |
| 72 | +## Vue3 |
| 73 | + |
| 74 | +```ts |
| 75 | +// main.ts |
| 76 | +import { createApp } from 'vue'; |
| 77 | +import VueSource from "unplugin-vue-source/vue"; |
| 78 | +import App from "./App.vue"; |
| 79 | + |
| 80 | +const app = createApp(App); |
| 81 | +app.use(VueSource); |
| 82 | +app.mount("#app"); |
| 83 | +``` |
| 84 | + |
| 85 | +## Plugins |
| 86 | + |
| 87 | +<details> |
| 88 | +<summary>Vite</summary><br> |
| 89 | + |
| 90 | +```ts |
| 91 | +// vite.config.ts |
| 92 | +import VueSource from "unplugin-vue-source/vite"; |
| 93 | + |
| 94 | +export default defineConfig({ |
| 95 | + plugins: [ |
| 96 | + VueSource({ /* options */ }), |
| 97 | + // other plugins |
| 98 | + ], |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | +<br></details> |
| 103 | + |
| 104 | +<details> |
| 105 | +<summary>Rollup</summary><br> |
| 106 | + |
| 107 | +```ts |
| 108 | +// rollup.config.js |
| 109 | +import VueSource from "unplugin-vue-source/rollup"; |
| 110 | + |
| 111 | +export default { |
| 112 | + plugins: [ |
| 113 | + VueSource({ /* options */ }), |
| 114 | + // other plugins |
| 115 | + ], |
| 116 | +}; |
| 117 | +``` |
| 118 | + |
| 119 | +<br></details> |
| 120 | + |
| 121 | +<details> |
| 122 | +<summary>Webpack</summary><br> |
| 123 | + |
| 124 | +```ts |
| 125 | +// webpack.config.js |
| 126 | +module.exports = { |
| 127 | + plugins: [ |
| 128 | + require("unplugin-vue-source/webpack")({ /* options */ }), |
| 129 | + // other plugins |
| 130 | + ], |
| 131 | +}; |
| 132 | +``` |
| 133 | + |
| 134 | +<br></details> |
| 135 | + |
| 136 | +<details> |
| 137 | +<summary>Rspack</summary><br> |
| 138 | + |
| 139 | +```ts |
| 140 | +// rspack.config.js |
| 141 | +module.exports = { |
| 142 | + plugins: [ |
| 143 | + require("unplugin-vue-source/rspack")({ /* options */ }), |
| 144 | + // other plugins |
| 145 | + ], |
| 146 | +}; |
| 147 | +``` |
| 148 | + |
| 149 | +<br></details> |
| 150 | + |
| 151 | +<details> |
| 152 | +<summary>Vue CLI</summary><br> |
| 153 | + |
| 154 | +```ts |
| 155 | +// vue.config.js |
| 156 | +module.exports = { |
| 157 | + configureWebpack: { |
| 158 | + plugins: [ |
| 159 | + require("unplugin-vue-source/webpack")({ /* options */ }), |
| 160 | + // other plugins |
| 161 | + ], |
| 162 | + }, |
| 163 | +}; |
| 164 | +``` |
| 165 | + |
| 166 | +<br></details> |
| 167 | + |
| 168 | +<details> |
| 169 | +<summary>esbuild</summary><br> |
| 170 | + |
| 171 | +```ts |
| 172 | +// esbuild.config.js |
| 173 | +import { build } from "esbuild"; |
| 174 | +import VueSource from "unplugin-vue-source/esbuild"; |
| 175 | + |
| 176 | +build({ |
| 177 | + plugins: [ |
| 178 | + VueSource({ /* options */ }), |
| 179 | + // other plugins |
| 180 | + ], |
| 181 | +}); |
| 182 | +``` |
| 183 | + |
| 184 | +<br></details> |
| 185 | + |
| 186 | + ## Configuration |
| 187 | + |
| 188 | +The following show the default values of the configuration |
| 189 | + |
| 190 | +```ts |
| 191 | +VueSource({ |
| 192 | + // source root path |
| 193 | + root: process.cwd(), |
| 194 | + |
| 195 | + // generate sourceMap |
| 196 | + sourceMap: false, |
| 197 | +}) |
| 198 | +``` |
0 commit comments