├── .editorconfig ├── .gitattributes ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── babel.config.js ├── circle.yml ├── example ├── App.vue.js ├── Welcome.vue.js ├── index.js └── poi.config.js ├── index.js ├── lib ├── attrs.js ├── compile.js └── loader.js ├── loader.js ├── package.json ├── test ├── __snapshots__ │ └── compile.test.js.snap └── compile.test.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "bracketSpacing": true 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) EGOIST <0x142857@gmail.com> (https://egoist.sh) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lit-vue 2 | 3 | [![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) 4 | 5 | **Please consider [donating](https://www.patreon.com/egoist) to this project's author, [EGOIST](#author), to show your ❤️ and support.** 6 | 7 | ## Motivation 8 | 9 | - Use all Vue SFC features in JavaScript / TypeScript files 10 | - Type-safe Vue templates ([#1](https://github.com/egoist/lit-vue/issues/1)) 11 | 12 | Combine `vue-loader` and `lit-vue/loader` to make the dream come to reality. 13 | 14 | ## Install 15 | 16 | ```bash 17 | yarn add lit-vue --dev 18 | ``` 19 | 20 | ## Example 21 | 22 | Previously you can use `.vue` single-file component like this: 23 | 24 | ```vue 25 | 32 | 33 | 47 | 48 | 53 | ``` 54 | 55 | Now with `lit-vue` you can use `.js` and `.ts` extensions: 56 | 57 | ```js 58 | import { html } from 'lit-vue' 59 | 60 | html` 61 | 68 | 69 | 74 | ` 75 | 76 | export default { 77 | data() { 78 | return { 79 | count: 0 80 | } 81 | }, 82 | methods: { 83 | inc() { 84 | this.count++ 85 | } 86 | } 87 | } 88 | ``` 89 | 90 |
You might need to configure the ESLint rule: no-unused-expressions
91 | 92 | 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: 93 | 94 | 1. Disable this rule for tagged template expression in your ESLint config 95 | 96 | ```json 97 | { 98 | "rules": { 99 | "no-unused-expressions": ["error", { "allowTaggedTemplates": true }] 100 | } 101 | } 102 | ``` 103 | 104 | 2. Or export it 105 | 106 | ```js 107 | export const template = html` 108 | 111 | ` 112 | ``` 113 | 114 | 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. 115 | 116 | 3. Or use it as component option 117 | 118 | ```js 119 | const template = html` 120 | 123 | ` 124 | 125 | export default { 126 | template, 127 | data() { 128 | return { 129 | count: 0 130 | } 131 | } 132 | } 133 | ``` 134 | 135 | Similar to #2, this may look more natural because `template` is a legit Vue component option. 136 | 137 |
138 | 139 | ## How to use 140 | 141 | ### Use with webpack 142 | 143 | ```js 144 | module.exports = { 145 | module: { 146 | rules: [ 147 | { 148 | // Match .js .ts files 149 | test: [/\.[jt]s$/], 150 | // Exclude .vue.js .vue.ts files 151 | // Since we want lit-vue to transform them into Vue SFC instead 152 | exclude: [/\.vue.[jt]s/] 153 | loader: 'babel-loader' // Use your desired loader 154 | }, 155 | // Handle .vue.js .vue.ts with lit-vue/loader and vue-loader 156 | { 157 | test: [/\.vue.[jt]s$/], 158 | use: [ 159 | 'vue-loader', 160 | 'lit-vue/loader' 161 | ] 162 | }, 163 | // This rule is also necessary even if you don't directly use .vue files 164 | { 165 | test: /\.vue$/, 166 | loader: 'vue-loader' 167 | } 168 | ] 169 | } 170 | } 171 | ``` 172 | 173 | 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! 174 | 175 | ### Optional `