generated from FriendsOfREDAXO/rex_repo_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
114 lines (103 loc) · 3.26 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { defineConfig, loadEnv } from 'vite'
import liveReload from 'vite-plugin-live-reload'
import copy from 'rollup-plugin-copy'
import path from 'path'
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
return defineConfig({
plugins: [
//vue(),
liveReload([
__dirname + '/**/*.php',
__dirname +
'/src/**/(*.svg|*.png|*.jpg|*.jpeg|*.webp|*.avif|*.gif|*.woff|*.woff2)',
__dirname + '/var/cache/addons/(structure|url)/**'
])
],
css: {
modules: {
scopeBehaviour: 'global'
//generateScopedName: '[local]_[hash:base64:5]'
}
},
// config
publicDir: path.resolve(__dirname, 'dev'),
base:
process.env.NODE_ENV === 'development' ? '/' : process.env.VITE_DIST_DIR,
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }]
},
build: {
// output dir for production build
outDir: path.resolve(
__dirname,
'.' + process.env.VITE_PUBLIC_DIR + process.env.VITE_DIST_DIR
),
assetsDir: '',
emptyOutDir: true,
// emit manifest so PHP can find the hashed files
manifest: false,
// esbuild target
// target: 'es2020',
// our entry
rollupOptions: {
// cache: false,
input: {
formslider: path.resolve(__dirname + process.env.VITE_ENTRY_POINT),
fsm: path.resolve(__dirname + process.env.VITE_SECONDARY_ENTRY_POINT)
},
output: [
{
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`
}
],
plugins: [
copy({
targets: [
{
src: 'src/img/**/*',
dest: 'assets/img'
}
],
hook: 'writeBundle'
})
]
}
// minifying switch
// minify: true,
},
server: {
origin: `${process.env.VITE_DEV_SERVER}:${process.env.VITE_DEV_SERVER_PORT}`, // required to load scripts from custom host
cors: {
origin: '*',
// methods: ["GET", "POST"],
// allowedHeaders: ["Content-Type", "Authorization"],
preflightContinue: true
},
// we need a strict port to match on PHP side
// change freely, but update in your functions.php to match the same port
strictPort: true,
port: process.env.VITE_DEV_SERVER_PORT,
// serve over http
https: false
// serve over httpS
// to generate localhost certificate follow the link:
// https://github.com/FiloSottile/mkcert - Windows, MacOS and Linux supported - Browsers Chrome, Chromium and Firefox (FF MacOS and Linux only)
// installation example on Windows 10:
// > choco install mkcert (this will install mkcert)
// > mkcert -install (global one time install)
// > mkcert localhost (in project folder files localhost-key.pem & localhost.pem will be created)
// uncomment below to enable https
//https: {
// key: fs.readFileSync('localhost-key.pem'),
// cert: fs.readFileSync('localhost.pem'),
//},
// hmr: {
// host: 'localhost'
// //port: 443
// }
}
})
}