|
| 1 | +import { defineConfig, Plugin } from 'vite'; |
| 2 | +import react from '@vitejs/plugin-react'; |
| 3 | +import { resolve } from 'path'; |
| 4 | +import { existsSync } from 'fs'; |
| 5 | +import dts from 'vite-plugin-dts'; |
| 6 | + |
| 7 | +// Ignore SCSS during JS lib build |
| 8 | +const ignoreScssPlugin = (): Plugin => ({ |
| 9 | + name: 'spc-ignore-scss', |
| 10 | + load(id) { |
| 11 | + if (id.endsWith('.scss')) return { code: '' }; |
| 12 | + } |
| 13 | +}); |
| 14 | + |
| 15 | +// Resolve '@' alias: in monorepo use root src; in split use local src |
| 16 | +const monorepoSrc = resolve(__dirname, '../../../src'); |
| 17 | +const localSrc = resolve(__dirname, '../src'); |
| 18 | +const atAlias = existsSync(monorepoSrc) ? monorepoSrc : localSrc; |
| 19 | + |
| 20 | +export default defineConfig({ |
| 21 | + plugins: [ |
| 22 | + ignoreScssPlugin(), |
| 23 | + react({ jsxRuntime: 'classic' }), |
| 24 | + dts({ |
| 25 | + entryRoot: resolve(__dirname, '../src'), |
| 26 | + outDir: resolve(__dirname, '../dist'), |
| 27 | + tsconfigPath: resolve(__dirname, '../tsconfig.json'), |
| 28 | + copyDtsFiles: true |
| 29 | + }) |
| 30 | + ], |
| 31 | + resolve: { |
| 32 | + alias: { |
| 33 | + '@': atAlias |
| 34 | + } |
| 35 | + }, |
| 36 | + build: { |
| 37 | + lib: { |
| 38 | + entry: { |
| 39 | + index: resolve(__dirname, '../src/index.ts'), |
| 40 | + engine: resolve(__dirname, '../src/engine/index.ts'), |
| 41 | + icons: resolve(__dirname, '../src/icons/index.ts') |
| 42 | + }, |
| 43 | + formats: ['es'], |
| 44 | + fileName: (_format, entryName) => { |
| 45 | + if (entryName === 'index') return 'index.esm.js'; |
| 46 | + return `${entryName}/index.js`; |
| 47 | + } |
| 48 | + }, |
| 49 | + rollupOptions: { |
| 50 | + external: [ |
| 51 | + 'react', |
| 52 | + 'react-dom', |
| 53 | + 'react/jsx-runtime', |
| 54 | + 'react/jsx-dev-runtime' |
| 55 | + ] |
| 56 | + }, |
| 57 | + sourcemap: true, |
| 58 | + copyPublicDir: false, |
| 59 | + outDir: resolve(__dirname, '../dist'), |
| 60 | + emptyOutDir: true |
| 61 | + } |
| 62 | +}); |
0 commit comments