|
| 1 | +# lit-vue |
| 2 | + |
| 3 | +[](https://npmjs.com/package/lit-vue) [](https://npmjs.com/package/lit-vue) [](https://circleci.com/gh/egoist/lit-vue/tree/master) [](https://patreon.com/egoist) [](https://chat.egoist.moe) |
| 4 | + |
| 5 | +**Please consider [donating](https://www.patreon.com/egoist) to this project's author, [EGOIST](#author), to show your ❤️ and support.** |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +All the features of `.vue` SFC are now available in your `.js` and `.ts` files. |
| 10 | + |
| 11 | +Combine `vue-loader` and `lit-vue/loader` to make the dream come to reality. |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +```bash |
| 16 | +yarn add lit-vue --dev |
| 17 | +``` |
| 18 | + |
| 19 | +## Example |
| 20 | + |
| 21 | +Previously you can use `.vue` single-file component like this: |
| 22 | + |
| 23 | +```vue |
| 24 | +<template> |
| 25 | + <div> |
| 26 | + <h1>hello</h1> |
| 27 | + <hr /> |
| 28 | + <button @click="inc">{{ count }}</button> |
| 29 | + </div> |
| 30 | +</template> |
| 31 | +
|
| 32 | +<script> |
| 33 | +export default { |
| 34 | + template, |
| 35 | + data() { |
| 36 | + return { |
| 37 | + count: 0 |
| 38 | + } |
| 39 | + }, |
| 40 | + methods: { |
| 41 | + inc() { |
| 42 | + this.count++ |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +</script> |
| 47 | +
|
| 48 | +<style scoped> |
| 49 | +h1 { |
| 50 | + color: red; |
| 51 | +} |
| 52 | +</style> |
| 53 | +``` |
| 54 | + |
| 55 | +Now with `lit-html` you can use `.js` and `.ts` extensions: |
| 56 | + |
| 57 | +```js |
| 58 | +import html from 'lit-vue/html' |
| 59 | + |
| 60 | +const template = html` |
| 61 | + <div> |
| 62 | + <h1>hello</h1> |
| 63 | + <hr /> |
| 64 | + <button @click="inc">{{ count }}</button> |
| 65 | + </div> |
| 66 | +
|
| 67 | + <style scoped> |
| 68 | + h1 { |
| 69 | + color: red; |
| 70 | + } |
| 71 | + </style> |
| 72 | +` |
| 73 | + |
| 74 | +export default { |
| 75 | + template, |
| 76 | + data() { |
| 77 | + return { |
| 78 | + count: 0 |
| 79 | + } |
| 80 | + }, |
| 81 | + methods: { |
| 82 | + inc() { |
| 83 | + this.count++ |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## How to use |
| 90 | + |
| 91 | +### Use with webpack |
| 92 | + |
| 93 | +```js |
| 94 | +module.exports = { |
| 95 | + module: { |
| 96 | + rules: [ |
| 97 | + { |
| 98 | + // Match .js .ts files |
| 99 | + test: [/\.[jt]s$/], |
| 100 | + // Excude .vue.js .vue.ts files |
| 101 | + // Since we want lit-vue to transform them into Vue SFC instead |
| 102 | + exclude: [/\.vue.[jt]s/] |
| 103 | + loader: 'babel-loader' // Use your desired loader |
| 104 | + }, |
| 105 | + // Handle .vue.js .vue.ts with lit-vue/loader and vue-loader |
| 106 | + { |
| 107 | + test: [/\.vue.[jt]s$/], |
| 108 | + use: [ |
| 109 | + 'vue-loader', |
| 110 | + 'lit-vue/loader' |
| 111 | + ] |
| 112 | + }, |
| 113 | + // This rule is also necessary even if you don't directly use .vue files |
| 114 | + { |
| 115 | + test: /\.vue$/, |
| 116 | + loader: 'vue-loader' |
| 117 | + } |
| 118 | + ] |
| 119 | + } |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +That's it, [all the goodies](https://vue-loader.vuejs.org/) of `.vue` SFC are available in your `.vue.js` and `.vue.ts` files now! |
| 124 | + |
| 125 | +### Syntax higlighting |
| 126 | + |
| 127 | +To highlight the code inside `html` template tag, you can use following editor plugins: |
| 128 | + |
| 129 | +- VSCode: [lit-html](https://marketplace.visualstudio.com/items?itemName=bierner.lit-html) |
| 130 | +- Something is missing? Send a PR to add it here! |
| 131 | + |
| 132 | +## Contributing |
| 133 | + |
| 134 | +1. Fork it! |
| 135 | +2. Create your feature branch: `git checkout -b my-new-feature` |
| 136 | +3. Commit your changes: `git commit -am 'Add some feature'` |
| 137 | +4. Push to the branch: `git push origin my-new-feature` |
| 138 | +5. Submit a pull request :D |
| 139 | + |
| 140 | +## Author |
| 141 | + |
| 142 | +**lit-vue** © EGOIST, Released under the [MIT](./LICENSE) License.<br> |
| 143 | +Authored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/lit-vue/contributors)). |
| 144 | + |
| 145 | +> [Website](https://egoist.sh) · GitHub [@EGOIST](https://github.com/egoist) · Twitter [@\_egoistlily](https://twitter.com/_egoistlily) |
0 commit comments