feat: add basic-jsx and basic-template examples

- basic-jsx: Counter + Clock with defineComponent() + JSX
- basic-template: Counter + Clock with .vue SFC + <template>
- Both demonstrate HMR via vue-tui dev
- Fix vite-plugin: strip build.lib and external config for bundledDev,
  add node builtins resolveId to prevent browser-external shimming
- Remove old hmr-demo example (superseded by basic-template)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-24 21:21:08 +08:00
parent e8ef31814a
commit 020fd0d85a
22 changed files with 333 additions and 92 deletions
+40 -21
View File
@@ -1,29 +1,48 @@
import type { Plugin } from "vite";
import { builtinModules } from "node:module";
export interface VueTuiDevPluginOptions {
entry?: string;
}
export function vueTuiDevPlugin(options?: VueTuiDevPluginOptions): Plugin {
return {
name: "vue-tui:dev",
config() {
return {
experimental: { bundledDev: true },
build: {
modulePreload: false,
...(options?.entry ? { lib: { entry: options.entry } } : {}),
},
define: {
__VUE_TUI_DEV__: "true",
},
resolve: {
conditions: ["node"],
},
server: {
strictPort: true,
},
};
const nodeBuiltins = new Set([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
export function vueTuiDevPlugin(_options?: VueTuiDevPluginOptions): Plugin[] {
return [
{
name: "vue-tui:node-builtins",
enforce: "pre",
resolveId(id) {
if (nodeBuiltins.has(id)) {
return { id: id.startsWith("node:") ? id : `node:${id}`, external: true };
}
},
},
};
{
name: "vue-tui:dev",
config(config) {
// bundledDev uses index.html as entry, not build.lib
if (config.build?.lib) {
config.build.lib = undefined;
}
// bundledDev bundles everything — strip user's external config
if (config.build?.rollupOptions) {
config.build.rollupOptions.external = undefined;
}
return {
experimental: { bundledDev: true },
build: {
modulePreload: false,
},
define: {
__VUE_TUI_DEV__: "true",
},
server: {
strictPort: true,
},
};
},
},
];
}