-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
76 lines (72 loc) · 1.81 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
/**
* RSD WordPress - Vite configuration file
* https://vitejs.dev/config/
*
* @module
* @since 0.8.0
* @license Apache-2.0
*/
import { defineConfig } from 'vite';
import postcss from 'postcss';
import browserslist from 'browserslist';
import { browserslistToTargets } from 'lightningcss';
import autoprefixer from 'autoprefixer';
import { babel } from '@rollup/plugin-babel';
import { resolve } from 'path';
const isProduction = process.env.NODE_ENV === 'production';
const entryName = process.env.ENTRY_NAME || 'rsd-wordpress';
const entryFile = process.env.ENTRY_FILE || 'src/index.js';
const fileName = ( name, isMinified, ext ) => {
const min = isMinified ? '.min' : '';
return `${ name }${ min }.${ ext }`;
};
export default defineConfig( {
optimizeDeps: {
exclude: [ 'jquery' ],
},
define: {
'process.env': process.env,
$: 'window.jQuery',
jQuery: 'window.jQuery',
},
build: {
emptyOutDir: false,
minify: isProduction,
cssMinify: isProduction ? 'lightningcss' : false,
sourcemap: isProduction,
lib: {
name: entryName,
entry: { [ entryName ]: resolve( __dirname, entryFile ) },
},
rollupOptions: {
output: {
format: 'iife',
entryFileNames: ( { name } ) =>
fileName( name, isProduction, 'js' ),
chunkFileNames: ( { name } ) =>
fileName( name, isProduction, 'js' ),
assetFileNames: ( assetInfo ) => {
const ext = assetInfo.name.split( '.' ).pop();
return fileName( entryName, isProduction, ext );
},
},
plugins: isProduction
? [
babel( {
exclude: 'node_modules/**',
babelHelpers: 'bundled',
} ),
]
: [],
},
css: {
postcss: {
plugins: [ postcss(), autoprefixer() ],
},
transformer: 'lightningcss',
lightningcss: {
targets: browserslistToTargets( browserslist( 'defaults' ) ),
},
},
},
} );