-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathvite.config.js
More file actions
78 lines (77 loc) · 1.89 KB
/
vite.config.js
File metadata and controls
78 lines (77 loc) · 1.89 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { defineConfig } from 'vite';
import { v4wp } from '@kucrut/vite-for-wp';
import { rmSync } from 'node:fs';
import preact from '@preact/preset-vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
export default defineConfig( {
plugins: [
preact(),
v4wp( {
input: {
main: 'src/index.tsx',
'query-monitor': 'assets/query-monitor.css',
'toolbar': 'assets/toolbar.css',
},
outDir: 'assets/build',
} ),
{
name: 'clean-build-dir',
configureServer() {
rmSync( 'assets/build', { recursive: true, force: true } );
},
},
{
name: 'shadow-dom-css-hmr',
handleHotUpdate( { file, server } ) {
if ( file.endsWith( '/assets/query-monitor.css' ) ) {
server.ws.send( {
type: 'custom',
event: 'qm:css-update',
} );
}
},
},
{
name: 'no-manifest',
config() {
return {
build: {
manifest: false,
},
};
},
},
],
server: {
cors: true,
},
build: {
sourcemap: false,
target: browserslistToEsbuild(),
// Terser is used instead of esbuild for minification in order to preserve
// wp i18n function names so translate.wordpress.org can extract them.
minify: 'terser',
terserOptions: {
mangle: {
// Prevent i18n function names from being shortened.
reserved: [ '__', '_x', '_n', '_nx', 'sprintf' ],
},
compress: {
// Prevent ternary expressions from being moved inside i18n
// function arguments, which makes them unextractable.
conditionals: false,
},
format: {
// Preserve translators comments for wp i18n string extraction.
comments: /translators:/i,
preamble: '/* This is the built version of the Preact app for Query Monitor. The source code is available here: https://github.com/johnbillion/query-monitor */',
},
},
rollupOptions: {
output: {
entryFileNames: 'query-monitor.js',
assetFileNames: '[name][extname]',
},
},
},
} );