-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
54 lines (48 loc) · 1.3 KB
/
vite.config.js
File metadata and controls
54 lines (48 loc) · 1.3 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
import { defineConfig, loadEnv } from 'vite'
import path from 'path'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const isDev = mode === 'development';
const isWordPress = env.VITE_ENV === 'wordpress';
const isStandard = env.VITE_ENV === 'standard';
if (!isWordPress && !isStandard) {
throw new Error('Unknown VITE_ENV. Use "wordpress" or "standard".');
}
if (isWordPress && isDev) {
throw new Error('Whoops... Dev server is temporarily not supported for WordPress. Only build is allowed atm.');
}
let base = '/';
let outDir = 'dist';
if (isWordPress) {
base = '/wp-content/plugins/feedback-plugin/';
outDir = 'feedback-plugin';
} else if (isStandard) {
base = './';
outDir = 'public';
}
return {
base,
publicDir: false,
define: {
'import.meta.env.VITE_ENV': JSON.stringify(env.VITE_ENV),
},
build: {
outDir,
emptyOutDir: false,
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
},
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: 'assets/[name].js',
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
};
});