-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathvite.config.scripts.js
More file actions
37 lines (35 loc) · 1.3 KB
/
vite.config.scripts.js
File metadata and controls
37 lines (35 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
import { defineConfig } from 'vite';
// Although WP has wp_enqueue_script_module to be able to load an ES scripts.min.js directly as a js module,
// WP doesn't let module scripts depend on classic scripts (scripts.min.js depending on jquery) or
// vice versa (modular-list.js depending on scripts.min.js). So at least for now, we need to depend on
// building a legacy IIFE script file that many wp scripts depend on via the 'site-js' handle.
// This doesn't seem possible alongside the processing of SCSS, so we're using this separate Vite build
// to handle just the bundling of the scripts.
export default defineConfig(({ mode }) => {
return {
root: '.',
build: {
outDir: 'dt-assets/build/js',
emptyOutDir: true,
minify: true,
sourcemap: true,
rollupOptions: {
input: {
scripts: 'dt-assets/js/main.js',
},
// Externalize jQuery since WordPress provides it
external: ['jquery'],
output: {
format: 'iife',
globals: {
jquery: 'jQuery',
},
// Remove the hashes from the filenames for WordPress predictability
entryFileNames: '[name].min.js',
chunkFileNames: '[name]-[hash].js',
assetFileNames: '../assets/[name].[ext]',
},
},
},
};
});