Skip to content

Commit 5c06993

Browse files
committed
fix(demo): keep build output out of demo sources
Write the built demo to demo/dist instead of demo/ so build-demo no longer deletes the checked-in demo source files. Also switch the demo image reference to use new URL(..., import.meta.url).href, which avoids the TypeScript 5.9 asset import resolution failure seen in CI during check-types. Add a regression test for the demo build config and ignore only demo/dist.
1 parent 5747ed2 commit 5c06993

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
node_modules/
33
dist/
44
coverage/
5-
demo/
5+
demo/dist/
66
*.log

demo/Demo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import {
5151
} from '../src';
5252

5353
import './Demo.css';
54-
import exampleImage from './react-share-pin-example.png';
54+
55+
const exampleImage = new URL('./react-share-pin-example.png', import.meta.url).href;
5556

5657
export function Demo() {
5758
const shareUrl = 'http://github.com';

test/DemoBuildConfig.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { readFile } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { describe, expect, it } from 'vitest';
5+
6+
describe('demo build config', () => {
7+
it('writes built assets under demo/dist without overwriting demo sources', async () => {
8+
const workspaceRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
9+
const configPath = path.join(workspaceRoot, 'vite.demo.config.js');
10+
const configSource = await readFile(configPath, 'utf8');
11+
12+
expect(configSource).toContain("root: './demo'");
13+
expect(configSource).toContain("outDir: './dist'");
14+
expect(configSource).not.toContain("outDir: '../demo'");
15+
});
16+
});

vite.demo.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineConfig({
55
root: './demo',
66
plugins: [react()],
77
build: {
8-
outDir: '../demo',
8+
outDir: './dist',
99
emptyOutDir: true,
1010
cssMinify: false,
1111
},

0 commit comments

Comments
 (0)