Skip to content

Commit c971161

Browse files
authored
Merge pull request #430 from whuang37/build-sdk-only
New Build Option
2 parents 11c0121 + 32bde81 commit c971161

2 files changed

Lines changed: 78 additions & 69 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build:watch": "rollup -c -w",
1515
"serve": "http-server --cors -a 127.0.0.1 -p 8080",
1616
"build": "echo \"Building xrblocks.js...\" && rollup -c --failAfterWarnings",
17+
"build:sdk": "rollup -c --failAfterWarnings --forceExit --environment XRBLOCKS_BUILD:sdk",
1718
"prepare": "npm run build",
1819
"lint": "eslint src",
1920
"format": "npm run format:fix",

rollup.config.js

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {dts} from 'rollup-plugin-dts';
1010
// Read the version from package.json
1111
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
1212
const version = packageJson.version;
13+
const buildTarget = process.env.XRBLOCKS_BUILD ?? 'all';
14+
const buildExamples = buildTarget !== 'sdk';
1315

1416
// Get the current commit ID (short hash)
1517
let commitId = 'unknown';
@@ -86,7 +88,7 @@ const xrblocksPackages = [
8688
/xrblocks\/addons\//,
8789
];
8890

89-
export default [
91+
const sdkBuilds = [
9092
{
9193
input: 'src/xrblocks.ts',
9294
external: externalPackages,
@@ -171,72 +173,78 @@ export default [
171173
}),
172174
],
173175
},
174-
// Enable demo projects (excluding those with a custom build system) to use TypeScript
175-
// and import it in their index.html via by referencing, e.g. `./build/main.js`.
176-
...globSync('demos/**/*.ts', {
177-
ignore: [
178-
'demos/**/node_modules/**',
179-
'demos/**/build/**',
180-
// Projects with a custom build system.
181-
],
182-
}).map((file) => ({
183-
input: file,
184-
external: () => true,
185-
output: {
186-
file: path.join(
187-
path.dirname(file),
188-
'build',
189-
path.basename(file).replace(/\.ts$/, '.js')
190-
),
191-
format: 'esm',
192-
},
193-
plugins: [
194-
typescript({
195-
tsconfig: false,
196-
include: [file],
197-
compilerOptions: {
198-
target: 'ES2022',
199-
module: 'ESNext',
200-
moduleResolution: 'bundler',
201-
esModuleInterop: true,
202-
forceConsistentCasingInFileNames: true,
203-
strict: true,
204-
skipLibCheck: true,
205-
declaration: false,
206-
},
207-
}),
208-
],
209-
})),
210-
// Enable demo projects (excluding those with a custom build system) to use TypeScript
211-
// and import it in their index.html via by referencing, e.g. `./build/main.js`.
212-
...globSync('samples/**/*.ts', {
213-
ignore: ['samples/**/node_modules/**', 'samples/**/build/**'],
214-
}).map((file) => ({
215-
input: file,
216-
external: () => true,
217-
output: {
218-
file: path.join(
219-
path.dirname(file),
220-
'build',
221-
path.basename(file).replace(/\.ts$/, '.js')
222-
),
223-
format: 'esm',
224-
},
225-
plugins: [
226-
typescript({
227-
tsconfig: false,
228-
include: [file],
229-
compilerOptions: {
230-
target: 'ES2022',
231-
module: 'ESNext',
232-
moduleResolution: 'bundler',
233-
esModuleInterop: true,
234-
forceConsistentCasingInFileNames: true,
235-
strict: true,
236-
skipLibCheck: true,
237-
declaration: false,
238-
},
239-
}),
240-
],
241-
})),
242176
];
177+
178+
// Enable demo projects (excluding those with a custom build system) to use TypeScript
179+
// and import it in their index.html via by referencing, e.g. `./build/main.js`.
180+
const demoBuilds = globSync('demos/**/*.ts', {
181+
ignore: [
182+
'demos/**/node_modules/**',
183+
'demos/**/build/**',
184+
// Projects with a custom build system.
185+
],
186+
}).map((file) => ({
187+
input: file,
188+
external: () => true,
189+
output: {
190+
file: path.join(
191+
path.dirname(file),
192+
'build',
193+
path.basename(file).replace(/\.ts$/, '.js')
194+
),
195+
format: 'esm',
196+
},
197+
plugins: [
198+
typescript({
199+
tsconfig: false,
200+
include: [file],
201+
compilerOptions: {
202+
target: 'ES2022',
203+
module: 'ESNext',
204+
moduleResolution: 'bundler',
205+
esModuleInterop: true,
206+
forceConsistentCasingInFileNames: true,
207+
strict: true,
208+
skipLibCheck: true,
209+
declaration: false,
210+
},
211+
}),
212+
],
213+
}));
214+
215+
// Enable sample projects to use TypeScript and import it in their index.html
216+
// via by referencing, e.g. `./build/main.js`.
217+
const sampleBuilds = globSync('samples/**/*.ts', {
218+
ignore: ['samples/**/node_modules/**', 'samples/**/build/**'],
219+
}).map((file) => ({
220+
input: file,
221+
external: () => true,
222+
output: {
223+
file: path.join(
224+
path.dirname(file),
225+
'build',
226+
path.basename(file).replace(/\.ts$/, '.js')
227+
),
228+
format: 'esm',
229+
},
230+
plugins: [
231+
typescript({
232+
tsconfig: false,
233+
include: [file],
234+
compilerOptions: {
235+
target: 'ES2022',
236+
module: 'ESNext',
237+
moduleResolution: 'bundler',
238+
esModuleInterop: true,
239+
forceConsistentCasingInFileNames: true,
240+
strict: true,
241+
skipLibCheck: true,
242+
declaration: false,
243+
},
244+
}),
245+
],
246+
}));
247+
248+
export default buildExamples
249+
? [...sdkBuilds, ...demoBuilds, ...sampleBuilds]
250+
: sdkBuilds.slice(0, 3);

0 commit comments

Comments
 (0)