-
-
Notifications
You must be signed in to change notification settings - Fork 185
feat(core): slim createTresApp alternative for tree-shakeable Three.js usage #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
94b2409
561b807
0f85cb8
3368c15
c55b3eb
3ddd081
7a143c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Bundle test — full (no :extends)</title> | ||
| <style> body { margin: 0; } </style> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main-full.ts"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Bundle test — TresCanvas (full THREE)</title> | ||
| <style> body { margin: 0; } </style> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main-slim.ts"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "bundle-test", | ||
| "type": "module", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build", | ||
| "build:slim": "vite build --mode slim", | ||
| "build:full": "vite build --mode full", | ||
| "build:createtres": "vite build --mode createtres", | ||
| "preview": "vite preview", | ||
| "build:tsdown:slim": "tsdown --config tsdown.slim.config.mts", | ||
| "build:tsdown:full": "tsdown --config tsdown.full.config.mts" | ||
| }, | ||
| "dependencies": { | ||
| "@tresjs/core": "workspace:^", | ||
| "vue": "catalog:vue" | ||
| }, | ||
| "devDependencies": { | ||
| "@vitejs/plugin-vue": "catalog:vite", | ||
| "rollup-plugin-visualizer": "catalog:build", | ||
| "tsdown": "catalog:build", | ||
| "unplugin-vue": "^7.1.1", | ||
| "vite": "catalog:vite", | ||
| "vue-tsc": "catalog:typescript" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Bundle test — createTresApp (tree-shaking)</title> | ||
| <style> body { margin: 0; } </style> | ||
| </head> | ||
| <body> | ||
| <canvas id="canvas"></canvas> | ||
| <script type="module" src="/src/main-slim.ts"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <script setup lang="ts"> | ||
| import { TresCanvas } from '@tresjs/core' | ||
| </script> | ||
|
|
||
| <template> | ||
| <TresCanvas window-size> | ||
| <TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" /> | ||
| <TresAmbientLight :intensity="1" /> | ||
| <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" /> | ||
| <TresMesh> | ||
| <TresBoxGeometry /> | ||
| <TresMeshStandardMaterial color="hotpink" /> | ||
| </TresMesh> | ||
| </TresCanvas> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <template> | ||
| <TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" /> | ||
| <TresAmbientLight :intensity="1" /> | ||
| <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" /> | ||
| <TresMesh> | ||
| <TresBoxGeometry /> | ||
| <TresMeshStandardMaterial color="hotpink" /> | ||
| </TresMesh> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { createApp } from 'vue' | ||
| import AppFull from './AppFull.vue' | ||
|
|
||
| createApp(AppFull).mount('#app') |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||
| /* import { | ||||||||||||||||||||||||||||||||||||||||
| AmbientLight, | ||||||||||||||||||||||||||||||||||||||||
| BoxGeometry, | ||||||||||||||||||||||||||||||||||||||||
| DirectionalLight, | ||||||||||||||||||||||||||||||||||||||||
| Mesh, | ||||||||||||||||||||||||||||||||||||||||
| MeshStandardMaterial, | ||||||||||||||||||||||||||||||||||||||||
| PerspectiveCamera, | ||||||||||||||||||||||||||||||||||||||||
| } from 'three' | ||||||||||||||||||||||||||||||||||||||||
| import { createTresApp } from '@tresjs/core/slim' | ||||||||||||||||||||||||||||||||||||||||
| import SceneCreateTres from './SceneCreateTres.vue' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const canvas = document.getElementById('canvas') as HTMLCanvasElement | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const root = createTresApp(canvas, { windowSize: true }) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| root | ||||||||||||||||||||||||||||||||||||||||
| .extend({ AmbientLight, BoxGeometry, DirectionalLight, Mesh, MeshStandardMaterial, PerspectiveCamera }) | ||||||||||||||||||||||||||||||||||||||||
| .render(SceneCreateTres) | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| import { WebGLRenderer } from 'three' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export default new WebGLRenderer({ canvas: document.getElementById('canvas') as HTMLCanvasElement }) | ||||||||||||||||||||||||||||||||||||||||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { defineConfig } from 'tsdown' | ||
| import { resolve } from 'node:path' | ||
| import { visualizer } from 'rollup-plugin-visualizer' | ||
|
|
||
| export default defineConfig({ | ||
| entry: { | ||
| full: './src/main-full.ts', | ||
| }, | ||
| outDir: 'dist-tsdown', | ||
| platform: 'browser', | ||
| plugins: [ | ||
| visualizer({ filename: 'stats-tsdown-full.html', open: false, gzipSize: true }), | ||
| ], | ||
| resolve: { | ||
| alias: { | ||
| '@tresjs/core/slim': resolve('./../../packages/core/src/slim.ts'), | ||
| '@tresjs/core': resolve('./../../packages/core/src/index.ts'), | ||
| }, | ||
| }, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { defineConfig } from 'tsdown' | ||
| import { resolve } from 'node:path' | ||
| import Vue from 'unplugin-vue/rolldown' | ||
| import { visualizer } from 'rollup-plugin-visualizer' | ||
|
|
||
| export default defineConfig({ | ||
| entry: { | ||
| slim: './src/main-slim.ts', | ||
| }, | ||
| outDir: 'dist-tsdown', | ||
| platform: 'neutral', | ||
| noExternal: [/./], | ||
| /* minify: true, */ | ||
| plugins: [ | ||
| Vue({ isProduction: true }), | ||
| visualizer({ filename: 'stats-tsdown-slim.html', open: false, gzipSize: true }), | ||
| ], | ||
| inputOptions: { | ||
| resolve: { | ||
| alias: { | ||
| '@tresjs/core/slim': resolve('./../../packages/core/src/slim.ts'), | ||
| '@tresjs/core': resolve('./../../packages/core/src/index.ts'), | ||
| }, | ||
| }, | ||
| }, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { templateCompilerOptions } from '@tresjs/core' | ||
| import vue from '@vitejs/plugin-vue' | ||
| import { resolve } from 'node:path' | ||
| import { defineConfig } from 'vite' | ||
| import { visualizer } from 'rollup-plugin-visualizer' | ||
|
|
||
| export default defineConfig(({ mode }) => ({ | ||
| plugins: [ | ||
| vue(templateCompilerOptions), | ||
| visualizer({ filename: `stats-${mode}.html`, open: false }), | ||
| ], | ||
| resolve: { | ||
| alias: { | ||
| '@tresjs/core/slim': resolve(__dirname, '../../packages/core/src/slim.ts'), | ||
| '@tresjs/core': resolve(__dirname, '../../packages/core/src/index.ts'), | ||
| }, | ||
| }, | ||
| build: { | ||
| target: 'esnext', | ||
| modulePreload: { polyfill: false }, | ||
| rollupOptions: { | ||
| input: resolve(__dirname, mode === 'full' ? 'full.html' : mode === 'slim' ? 'slim.html' : 'index.html'), | ||
| }, | ||
| }, | ||
| })) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <script setup lang="ts"> | ||
| import { OrbitControls } from '@tresjs/cientos' | ||
| </script> | ||
|
|
||
| <template> | ||
| <TresPerspectiveCamera :position="[5, 5, 5]" :look-at="[0, 0, 0]" /> | ||
| <TresGridHelper /> | ||
| <TresAmbientLight :intensity="1" /> | ||
| <TresDirectionalLight :position="[0, 8, 4]" :intensity="0.7" /> | ||
| <OrbitControls /> | ||
| <TresMesh> | ||
| <TresBoxGeometry /> | ||
| <TresMeshStandardMaterial color="hotpink" /> | ||
| </TresMesh> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <script setup lang="ts"> | ||
| import { onMounted, onUnmounted, ref } from 'vue' | ||
| import { createTresApp } from '@tresjs/core' | ||
| import { | ||
| AmbientLight, | ||
| BoxGeometry, | ||
| DirectionalLight, | ||
| GridHelper, | ||
| Mesh, | ||
| MeshStandardMaterial, | ||
| PerspectiveCamera, | ||
| } from 'three' | ||
| import Experience from './experience.vue' | ||
|
|
||
| const canvasRef = ref<HTMLCanvasElement>() | ||
| let root: ReturnType<typeof createTresApp> | ||
|
|
||
| onMounted(() => { | ||
| if (!canvasRef.value) { return } | ||
|
|
||
| root = createTresApp(canvasRef.value, { windowSize: true }) | ||
| root | ||
| .extend({ AmbientLight, BoxGeometry, DirectionalLight, GridHelper, Mesh, MeshStandardMaterial, PerspectiveCamera }) | ||
| .render(Experience) | ||
| }) | ||
|
|
||
| onUnmounted(() => { | ||
| root?.dispose() | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <canvas ref="canvasRef" /> | ||
| </template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue/suggestion/question: The bundle test pages throw an error and don't show anything. Shall we maybe not have the
bundle-testfolder in the repo? This might reduce maintenance work in the future.