Skip to content

Commit

Permalink
feat: export vue compiler options for Tres custom renderer (#324)
Browse files Browse the repository at this point in the history
* feat: export vue compiler options for Tres custom renderer

* docs: added vite config vue compiler options

* docs: Update docs/guide/index.md

Co-authored-by: Tino Koch <[email protected]>

---------

Co-authored-by: Tino Koch <[email protected]>
  • Loading branch information
alvarosabu and Tinoooo authored Jun 28, 2023
1 parent 9cc63d2 commit 66716d5
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"scss.lint.unknownAtRules": "ignore",
"css.lint.unknownAtRules": "ignore",
Expand Down
19 changes: 19 additions & 0 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ pnpm add @types/three -D
```
:::

## Vite

If you are using Vite, you have add the following to your `vite.config.ts`:

```ts
import { templateCompilerOptions } from '@tresjs/core'

export default defineConfig({
plugins: [
vue({
// Other config
...templateCompilerOptions
}),
],
}),
```

This is required to make the template compiler work with the custom renderer and not throw warnings on the console. For more info check [here](/guide/troubleshooting.html).

## Try it online

We have a brand new [StackBlitz](https://stackblitz.com/) starter to try TresJS online. Check it out:
Expand Down
8 changes: 3 additions & 5 deletions docs/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ Got to your `vite.config.ts` and add the following configuration to the `@vitejs
```ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { templateCompilerOptions } from '@tresjs/core'

export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => (tag.startsWith('Tres') && tag !== 'TresCanvas') || tag === 'primitive',
},
},
// Other config
...templateCompilerOptions,
}),
],
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"vite-plugin-inspect": "^0.7.29",
"vite-plugin-require-transform": "^1.0.17",
"vite-svg-loader": "^4.0.0",
"vitepress": "1.0.0-beta.2",
"vitepress": "1.0.0-beta.3",
"vitest": "^0.32.2",
"vue": "^3.3.4",
"vue-demi": "^0.14.5"
Expand Down
2 changes: 1 addition & 1 deletion playground/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
"watchSyncEffect": true,
"toValue": true
}
}
}
4 changes: 1 addition & 3 deletions playground/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

export {}

declare module '@vue/runtime-core' {
declare module 'vue' {
export interface GlobalComponents {
AnimatedModel: typeof import('./src/components/AnimatedModel.vue')['default']
Cameras: typeof import('./src/components/Cameras.vue')['default']
Expand Down
12 changes: 2 additions & 10 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import glsl from 'vite-plugin-glsl'
import UnoCSS from 'unocss/vite'
import { templateCompilerOptions } from '@tresjs/core'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
glsl(),
vue({
script: {
propsDestructure: true,
},
template: {
compilerOptions: {
isCustomElement: tag => (tag.startsWith('Tres') && tag !== 'TresCanvas' && tag !== 'TresLeches') || tag === 'primitive',
},
},
}),
vue(templateCompilerOptions),
AutoImport({
dts: true,
eslintrc: {
Expand Down
Loading

0 comments on commit 66716d5

Please sign in to comment.