返回 reveal.js
vite.config.ts
根目录 / vite.config.ts
1 import { resolve } from 'path';
2 import { ModuleFormat } from 'rollup';
3 import { defineConfig } from 'vite';
4 import dts from 'vite-plugin-dts';
5 import { rewriteLegacyCoreDtsPath } from './build/dts-paths.ts';
6
7 export const appendExtension = (format: ModuleFormat, name: String): string => {
8 if (format === 'es') {
9 return `${name}.mjs`;
10 } else {
11 return `${name}.js`;
12 }
13 };
14
15 export default defineConfig({
16 server: {
17 port: Number(process.env.npm_config_port || 8000),
18 },
19 build: {
20 target: ['es2015'],
21 emptyOutDir: true,
22 lib: {
23 formats: ['es', 'umd'],
24 entry: resolve(__dirname, 'js/index.ts'),
25 name: 'Reveal',
26 fileName: (format, entryName) => {
27 return appendExtension(format, 'reveal');
28 },
29 },
30 rollupOptions: {
31 output: {
32 assetFileNames: 'reveal.[ext]',
33 },
34 },
35 },
36 resolve: {
37 alias: {
38 // Matches the exported paths in package.json
39 'reveal.js/plugin': '/plugin',
40 'reveal.js': '/js',
41 'reveal.css': '/css/reveal.scss',
42 },
43 },
44 plugins: [
45 dts({
46 insertTypesEntry: true,
47 rollupTypes: false,
48 exclude: ['**/index.ts'],
49 copyDtsFiles: true,
50 beforeWriteFile(filePath, content) {
51 return {
52 filePath: rewriteLegacyCoreDtsPath(filePath),
53 content,
54 };
55 },
56 }),
57 ],
58 css: {
59 preprocessorOptions: {
60 scss: {
61 api: 'modern-compiler',
62 },
63 },
64 },
65 });
66
66 lines TYPESCRIPT