# lit-vue [![NPM version](https://badgen.net/npm/v/lit-vue)](https://npmjs.com/package/lit-vue) [![NPM downloads](https://badgen.net/npm/dm/lit-vue)](https://npmjs.com/package/lit-vue) [![CircleCI](https://badgen.net/circleci/github/egoist/lit-vue/master)](https://circleci.com/gh/egoist/lit-vue/tree/master) [![donate](https://badgen.net/badge/support%20me/donate/ff69b4)](https://patreon.com/egoist) [![chat](https://badgen.net/badge/chat%20on/discord/7289DA)](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 ``` Now with `lit-vue` you can use `.js` and `.ts` extensions: ```js import { html } from 'lit-vue' html` ` 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` ` ``` 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` ` 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 `