(options: PluginPackageOptions)
| 61 | * ``` |
| 62 | */ |
| 63 | export function pluginPreset(options: PluginPackageOptions): UserConfig { |
| 64 | const { |
| 65 | root, |
| 66 | entries = {}, |
| 67 | hasCSS = false, |
| 68 | external = [], |
| 69 | viteConfig = {} |
| 70 | } = options; |
| 71 | |
| 72 | const mainEntry = entries.main ?? 'src/index.ts'; |
| 73 | const runtimeEntry = entries.runtime ?? 'src/runtime.ts'; |
| 74 | const editorEntry = entries.editor ?? 'src/editor/index.ts'; |
| 75 | |
| 76 | // 构建入口点映射 |
| 77 | const entryPoints: Record<string, string> = { |
| 78 | index: resolve(root, mainEntry), |
| 79 | runtime: resolve(root, runtimeEntry), |
| 80 | 'editor/index': resolve(root, editorEntry) |
| 81 | }; |
| 82 | |
| 83 | const plugins: any[] = [ |
| 84 | dts({ |
| 85 | include: ['src'], |
| 86 | outDir: 'dist', |
| 87 | rollupTypes: false |
| 88 | }) |
| 89 | ]; |
| 90 | |
| 91 | // CSS 注入插件 |
| 92 | if (hasCSS) { |
| 93 | plugins.push(cssInjectPlugin()); |
| 94 | } |
| 95 | |
| 96 | return defineConfig({ |
| 97 | plugins, |
| 98 | esbuild: { |
| 99 | jsx: 'automatic', |
| 100 | }, |
| 101 | build: { |
| 102 | lib: { |
| 103 | entry: entryPoints, |
| 104 | formats: ['es'], |
| 105 | fileName: (_format: string, entryName: string) => `${entryName}.js` |
| 106 | }, |
| 107 | rollupOptions: { |
| 108 | external: [ |
| 109 | ...STANDARD_EXTERNALS, |
| 110 | ...external |
| 111 | ], |
| 112 | output: { |
| 113 | exports: 'named', |
| 114 | preserveModules: false, |
| 115 | // 禁用自动代码分割,所有共享代码内联到各入口 |
| 116 | manualChunks: () => undefined |
| 117 | } |
| 118 | }, |
| 119 | target: 'es2020', |
| 120 | minify: false, |
nothing calls this directly
no test coverage detected