-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
54 lines (47 loc) · 1.56 KB
/
vite.config.js
File metadata and controls
54 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// @see https://cn.vitejs.dev/guide/build.html#library-mode
import { resolve } from 'path';
import { defineConfig } from 'vite';
import pkg from './package.json';
const namespace = 'feng3d';
const external = pkg.standalone ? [] : Object.keys(pkg.dependencies || []);
const globals = () => namespace;
// 构建时在输出文件底部添加版本号打印
const versionBanner = `console.log("${pkg.name} v${pkg.version}");`;
export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/index.ts'),
name: namespace,
// the proper extensions will be added
fileName: 'index',
},
minify: false,
sourcemap: true,
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external,
output: {
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals,
// 在输出文件底部添加版本号打印
footer: versionBanner,
},
},
},
plugins: [
shaderToString(),
],
});
function shaderToString()
{
return {
name: 'vite-plugin-string',
async transform(source, id)
{
if (!['glsl', 'wgsl', 'vert', 'frag', 'vs', 'fs'].includes(id.split('.').pop())) return;
const esm = `export default \`${source}\`;`;
return { code: esm, map: { mappings: '' } };
},
};
}