-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathrollup.config.js
More file actions
252 lines (243 loc) · 7.48 KB
/
Copy pathrollup.config.js
File metadata and controls
252 lines (243 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import {execSync} from 'child_process';
import fs from 'fs';
import {globSync} from 'glob';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {dts} from 'rollup-plugin-dts';
// Read the version from package.json
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const version = packageJson.version;
const buildTarget = process.env.XRBLOCKS_BUILD ?? 'all';
const buildExamples = buildTarget !== 'sdk';
// Get the current commit ID (short hash)
let commitId = 'unknown';
try {
commitId = execSync('git rev-parse --short HEAD').toString().trim();
} catch {
console.error('Could not get the Git commit ID.');
}
const apache2License = ` * Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.`;
const bannerText = `/**
${apache2License}
*
* @file xrblocks.js
* @version v${version}
* @commitid ${commitId}
* @builddate ${new Date().toISOString()}
* @description XR Blocks SDK, built from source with the above commit ID.
* @agent When using with Gemini to create XR apps, use **Gemini Canvas** mode,
* and follow rules below:
* 1. Include the following importmap for maximum compatibility:
"three": "https://cdn.jsdelivr.net/npm/three@0.184.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.184.0/examples/jsm/",
"troika-three-text": "https://cdn.jsdelivr.net/gh/protectwise/troika@028b81cf308f0f22e5aa8e78196be56ec1997af5/packages/troika-three-text/src/index.js",
"troika-three-utils": "https://cdn.jsdelivr.net/gh/protectwise/troika@v0.52.4/packages/troika-three-utils/src/index.js",
"troika-worker-utils": "https://cdn.jsdelivr.net/gh/protectwise/troika@v0.52.4/packages/troika-worker-utils/src/index.js",
"bidi-js": "https://esm.sh/bidi-js@%5E1.0.2?target=es2022",
"webgl-sdf-generator": "https://esm.sh/webgl-sdf-generator@1.1.1/es2022/webgl-sdf-generator.mjs",
"lit": "https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js",
"lit/": "https://esm.run/lit@3/",
"three-pathfinding": "https://cdn.jsdelivr.net/npm/three-pathfinding@1.3.0/dist/three-pathfinding.module.js",
2. If the app focus on standalone objects, spawn it in front of the user in
WebXR and rescale to reasonable physical size. Wrap them with xb.ModelViewer
and make sure users can drag the platform to move it around in XR.
3. When rendering a large scene, remember users may navigate the scene in a
physical world space, also add locomotion methods like pinch to teleport.
4. Do not halluciate mode files --- use either public high-quality assets,
or generate from primitive shapes of use vox formats for voxels or
lego-styles.
*/`;
const externalPackages = [
'three',
/three\/addons\//,
'troika-three-text',
'@google/genai',
'@mediapipe/tasks-audio',
'@mediapipe/tasks-vision',
'openai',
'@sparkjsdev/spark',
/^lit(\/.*)?$/,
'@pmndrs/uikit',
'@preact/signals-core',
'rapier3d',
'three-mesh-bvh',
'three-pathfinding',
'vitest',
];
const xrblocksPackages = [
'xrblocks',
'uiblocks',
'netblocks',
/xrblocks\/addons\//,
];
const sdkBuilds = [
{
input: 'src/entry.ts',
external: externalPackages,
output: {
file: 'build/xrblocks.js',
format: 'esm',
banner: bannerText,
sourcemap: true,
},
plugins: [
typescript({
compilerOptions: {
composite: false,
declaration: false,
},
}),
],
},
{
input: 'src/entry.ts',
external: externalPackages,
output: {
file: 'build/xrblocks.d.ts',
format: 'esm',
banner: bannerText,
},
plugins: [dts()],
},
{
input: 'src/entry.ts',
external: externalPackages,
output: {
file: 'build/xrblocks.min.js',
format: 'esm',
sourcemap: true,
},
plugins: [
typescript({
compilerOptions: {
composite: false,
declaration: false,
},
}),
terser(),
],
watch: false, // Skip this rule when using watch.
},
{
input: Object.fromEntries(
globSync('src/addons/**/*.{js,ts}', {
ignore: [
'src/addons/**/cli/**',
'src/addons/**/server/**',
'src/addons/**/*.d.ts',
'src/addons/**/*.test.{js,ts}',
],
}).map((file) => [
// This removes `src/` as well as the file extension from
// each file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
),
// This expands the relative paths to absolute paths, so
// e.g. src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
])
),
external: [...externalPackages, ...xrblocksPackages],
output: {
dir: 'build/',
format: 'esm',
},
plugins: [
typescript({
tsconfig: 'src/addons/tsconfig.lib.json',
exclude: ['src/!(addons)/**/*.ts', 'src/*.ts'],
compilerOptions: {
declaration: true,
declarationDir: 'build/addons/',
},
}),
],
},
];
// Enable demo projects (excluding those with a custom build system) to use TypeScript
// and import it in their index.html via by referencing, e.g. `./build/main.js`.
const demoBuilds = globSync('demos/**/*.ts', {
ignore: [
'demos/**/node_modules/**',
'demos/**/build/**',
// Projects with a custom build system.
],
}).map((file) => ({
input: file,
external: () => true,
output: {
file: path.join(
path.dirname(file),
'build',
path.basename(file).replace(/\.ts$/, '.js')
),
format: 'esm',
},
plugins: [
typescript({
tsconfig: false,
include: [file],
compilerOptions: {
target: 'ES2022',
module: 'ESNext',
moduleResolution: 'bundler',
esModuleInterop: true,
forceConsistentCasingInFileNames: true,
strict: true,
skipLibCheck: true,
declaration: false,
},
}),
],
}));
// Enable sample projects to use TypeScript and import it in their index.html
// via by referencing, e.g. `./build/main.js`.
const sampleBuilds = globSync('samples/**/*.ts', {
ignore: ['samples/**/node_modules/**', 'samples/**/build/**'],
}).map((file) => ({
input: file,
external: () => true,
output: {
file: path.join(
path.dirname(file),
'build',
path.basename(file).replace(/\.ts$/, '.js')
),
format: 'esm',
},
plugins: [
typescript({
tsconfig: false,
include: [file],
compilerOptions: {
target: 'ES2022',
module: 'ESNext',
moduleResolution: 'bundler',
esModuleInterop: true,
forceConsistentCasingInFileNames: true,
strict: true,
skipLibCheck: true,
declaration: false,
},
}),
],
}));
export default buildExamples
? [...sdkBuilds, ...demoBuilds, ...sampleBuilds]
: sdkBuilds.slice(0, 3);