forked from gree/smfplayer.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.js
96 lines (90 loc) · 2.59 KB
/
vite.config.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fs from 'fs';
import { fileURLToPath, URL } from 'url';
import { defineConfig } from 'vite';
import banner from 'vite-plugin-banner';
import { checker } from 'vite-plugin-checker';
const pkg = require('./package.json');
const build = new Date().toISOString();
// Export vite config
export default defineConfig(async ({ mode, command }) => {
// Hook production build.
/** @type {UserConfig} https://vitejs.dev/config/ */
const config = {
// https://vitejs.dev/config/#base
base: './',
plugins: [
// vite-plugin-checker
// https://github.com/fi3ework/vite-plugin-checker
checker({
typescript: false,
vueTsc: false,
// eslint: { lintCommand: `eslint` }, // for example, lint .ts & .tsx
}),
// vite-plugin-banner
// https://github.com/chengpeiquan/vite-plugin-banner
banner(`/**
* ${pkg.name}
*
* @description ${pkg.description}
* @author iyama, Logue
* @license ${pkg.license}
* @version ${pkg.version}
* @see {@link ${pkg.homepage}}
*/
`),
],
publicDir: mode === 'docs',
// https://vitejs.dev/config/#server-options
server: {
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
cors: false,
},
resolve: {
// https://vitejs.dev/config/shared-options.html#resolve-alias
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'~': fileURLToPath(new URL('./node_modules', import.meta.url)),
},
extensions: ['.js'],
},
// Build Options
// https://vitejs.dev/config/#build-options
build: {
// Build Target
// https://vitejs.dev/config/build-options.html#build-target
target: 'esnext',
outDir: mode === 'docs' ? 'docs' : 'dist',
// Minify option
// https://vitejs.dev/config/build-options.html#build-minify
minify: true,
// https://vitejs.dev/config/build-options.html#build-lib
lib:
mode === 'docs'
? undefined
: {
entry: fileURLToPath(new URL('./src/index.js', import.meta.url)),
name: 'SMF',
formats: ['es', 'umd', 'iife'],
fileName: format => `smfplayer.${format}.js`,
},
},
esbuild: {
drop: command === 'serve' ? [] : ['console'],
},
};
// Write meta data.
fs.writeFileSync(
fileURLToPath(new URL('./src/meta.js', import.meta.url)),
`// This file is auto-generated by the build system.
const meta = {
version: '${pkg.version}',
date: '${build}',
};
export default meta;
`
);
return config;
});