# lit-vue
[](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)
**Please consider [donating](https://www.patreon.com/egoist) to this project's author, [EGOIST](#author), to show your ❤️ and support.**
## Motivation
- Use all Vue SFC features in JavaScript / TypeScript files
- Type-safe Vue templates ([#1](https://github.com/egoist/lit-vue/issues/1))
Combine `vue-loader` and `lit-vue/loader` to make the dream come to reality.
## Install
```bash
yarn add lit-vue --dev
```
## Example
Previously you can use `.vue` single-file component like this:
```vue
hello
```
Now with `lit-vue` you can use `.js` and `.ts` extensions:
```js
import { html } from 'lit-vue'
html`
hello
`
export default {
data() {
return {
count: 0
}
},
methods: {
inc() {
this.count++
}
}
}
```
You might need to configure the ESLint rule: no-unused-expressions
ESLint might complain about the the html`` expression not being used when you enabled the rule: [no-unused-expressions](http://eslint.cn/docs/rules/no-unused-expressions), there're three ways to solve it:
1. Disable this rule for tagged template expression in your ESLint config
```json
{
"rules": {
"no-unused-expressions": ["error", { "allowTaggedTemplates": true }]
}
}
```
2. Or export it
```js
export const template = html`
{{ count }}
`
```
You can just assign it to a variable and export it, though the exported variable will never be used. The return value of `html` tag is always undefined.
3. Or use it as component option
```js
const template = html`
{{ count }}
`
export default {
template,
data() {
return {
count: 0
}
}
}
```
Similar to #2, this may look more natural because `template` is a legit Vue component option.
## How to use
### Use with webpack
```js
module.exports = {
module: {
rules: [
{
// Match .js .ts files
test: [/\.[jt]s$/],
// Exclude .vue.js .vue.ts files
// Since we want lit-vue to transform them into Vue SFC instead
exclude: [/\.vue.[jt]s/]
loader: 'babel-loader' // Use your desired loader
},
// Handle .vue.js .vue.ts with lit-vue/loader and vue-loader
{
test: [/\.vue.[jt]s$/],
use: [
'vue-loader',
'lit-vue/loader'
]
},
// This rule is also necessary even if you don't directly use .vue files
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
}
}
```
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!
### Optional `` element
`` inside `html` is optional:
```js
html`
hello
`
// or
html`
hello
`
```
When using templates without `` tag, you have to use `` element to define custom blocks:
```js
html`
hello
{"en": {}}
`
// or
html`
hello
{"en": {}}
`
```
And in fact even the whole Vue template is optional in `html` tag, you can just use `
`
@Component({
props: {
name: String
}
})
export default class Welcome extends Vue {
// computed
get message() {
return 'hello ' + this.name
}
render() {
return