diff --git a/custom-elements-manifest.config.js b/custom-elements-manifest.config.js index a434d675..cb8c3ae4 100644 --- a/custom-elements-manifest.config.js +++ b/custom-elements-manifest.config.js @@ -1,6 +1,7 @@ import * as path from 'path'; import { customElementJetBrainsPlugin } from 'custom-element-jet-brains-integration'; import { customElementVsCodePlugin } from 'custom-element-vs-code-integration'; +import { customElementVuejsPlugin } from 'custom-element-vuejs-integration'; import { parse } from 'comment-parser'; import { pascalCase } from 'pascal-case'; import commandLineArgs from 'command-line-args'; @@ -218,6 +219,12 @@ export default { url: `https://shoelace.style/components/${tag.replace('sl-', '')}` }; } + }), + + customElementVuejsPlugin({ + outdir: './dist/types/vue', + fileName: 'index.d.ts', + componentTypePath: (_, tag) => `../../components/${tag.replace('sl-', '')}/${tag.replace('sl-', '')}.component.js` }) ] }; diff --git a/docs/pages/frameworks/vue.md b/docs/pages/frameworks/vue.md index 6416c2ce..d98ddb50 100644 --- a/docs/pages/frameworks/vue.md +++ b/docs/pages/frameworks/vue.md @@ -35,35 +35,22 @@ If you'd rather not use the CDN for assets, you can create a build task that cop ## Configuration -You'll need to tell Vue to ignore Shoelace components. This is pretty easy because they all start with `sl-`. - -```js -import { fileURLToPath, URL } from 'url'; - -import { defineConfig } from 'vite'; -import vue from '@vitejs/plugin-vue'; - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - vue({ - template: { - compilerOptions: { - isCustomElement: tag => tag.startsWith('sl-') - } - } - }) - ], - resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) - } - } -}); -``` +If you haven't configured your Vue.js project to work with custom elements/web components, follow [the instructions here](https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue) based on your project type to ensure your project will not throw an error when it encounters a custom element. Now you can start using Shoelace components in your app! +## Types + +Once you have configured your application for custom elements, you should be able to use Shoelace in your application without it causing any errors. Unfortunately, this doesn't register the custom elements to behave like components built using Vue. To provide autocomplete information and type safety for your components, you can import the Shoelace Vue types into your `tsconfig.json` to get better integration in your standard Vue and JSX templates. + +```json +{ + "compilerOptions": { + "types": ["@shoelace-style/shoelace/dist/types/vue"] + } +} +``` + ## Usage ### QR code generator example @@ -126,7 +113,7 @@ Are you using Shoelace with Vue? [Help us improve this page!](https://github.com ### Slots -To use Shoelace components with slots, follow the Vue documentation on using [slots with custom elements](https://vuejs.org/guide/extras/web-components.html#building-custom-elements-with-vue). +Slots in Shoelace/web components are functionally the same as basic slots in Vue. Slots can be assigned to elements using the `slot` attribute followed by the name of the slot it is being assigned to. Here is an example: diff --git a/package-lock.json b/package-lock.json index c18b0a91..a484a525 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "cspell": "^6.18.1", "custom-element-jet-brains-integration": "^1.4.0", "custom-element-vs-code-integration": "^1.2.1", + "custom-element-vuejs-integration": "^1.0.0", "del": "^7.1.0", "download": "^8.0.0", "esbuild": "^0.19.4", @@ -6469,6 +6470,30 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/custom-element-vuejs-integration": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/custom-element-vuejs-integration/-/custom-element-vuejs-integration-1.0.0.tgz", + "integrity": "sha512-L938mWj4c3gkBjoFKKtiBM6deVVzWf77EYSpt5622Cf1CYgeVysQdvqVWZ0HGWwoQe8t9gWLyAwBeELMMckkvA==", + "dev": true, + "dependencies": { + "prettier": "^2.7.1" + } + }, + "node_modules/custom-element-vuejs-integration/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/custom-elements-manifest": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/custom-elements-manifest/-/custom-elements-manifest-1.0.0.tgz", @@ -23658,6 +23683,23 @@ } } }, + "custom-element-vuejs-integration": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/custom-element-vuejs-integration/-/custom-element-vuejs-integration-1.0.0.tgz", + "integrity": "sha512-L938mWj4c3gkBjoFKKtiBM6deVVzWf77EYSpt5622Cf1CYgeVysQdvqVWZ0HGWwoQe8t9gWLyAwBeELMMckkvA==", + "dev": true, + "requires": { + "prettier": "^2.7.1" + }, + "dependencies": { + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true + } + } + }, "custom-elements-manifest": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/custom-elements-manifest/-/custom-elements-manifest-1.0.0.tgz", diff --git a/package.json b/package.json index 1e67edfe..0d86d6a0 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "start": "node scripts/build.js --serve", "build": "node scripts/build.js", "verify": "npm run prettier:check && npm run lint && npm run build && npm run test", + "postinstall": "npx playwright install", "prepublishOnly": "npm run verify", "prettier": "prettier --write --log-level=warn .", "prettier:check": "prettier --check --log-level=warn .", @@ -96,6 +97,7 @@ "cspell": "^6.18.1", "custom-element-jet-brains-integration": "^1.4.0", "custom-element-vs-code-integration": "^1.2.1", + "custom-element-vuejs-integration": "^1.0.0", "del": "^7.1.0", "download": "^8.0.0", "esbuild": "^0.19.4",