-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
78 lines (69 loc) · 2.29 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
import { defineConfig } from 'vite';
import { exec } from 'child_process';
import { existsSync } from 'fs';
import { normalize, resolve } from 'path';
export default ({ command }) => defineConfig({
publicDir: 'fake_dir_so_nothing_gets_copied',
base: command === 'serve' ? '' : '/source/assets/build/',
build: {
manifest: true,
outDir: resolve(__dirname + '/source/assets/build'),
assetsDir: '.',
rollupOptions: {
input: resolve(__dirname + '/source/_assets/js/main.js')
},
},
plugins: [
jigsaw()
]
});
function jigsaw() {
const bin = existsSync('./vendor/bin/jigsaw') ? normalize('./vendor/bin/jigsaw') : hasbin('jigsaw', (result) => {
if (result) return 'jigsaw';
console.error('Could not find Jigsaw; please install it with composer.');
process.exit(1);
});
const jigsaw = (env) => {
console.log('Starting Jigsaw build');
exec(`${bin} build -q ${env}`, (error, stdout, stderr) => {
console.log('Completed Jigsaw build');
error ? console.warn(`Error building Jigsaw site:\n${stderr}`) : console.log(stdout);
});
}
return {
name: 'jigsaw',
closeBundle() {
console.log('Build complete. Running binary command...');
jigsaw('production')
},
handleHotUpdate({ file , server }) {
if (file.includes('build_')) {
return;
}
if (file.includes('_tmp')) {
return;
}
jigsaw('local');
server.ws.send({ type: 'full-reload', path: '*' });
}
}
}
function hasbin(binaryName, callback) {
const isWindows = process.platform === 'win32';
const command = isWindows ? `where ${binaryName}` : `which ${binaryName}`;
exec(command, (err, stdout) => {
if (err) {
callback(false);
return;
}
const binaryPath = stdout.trim();
if (binaryPath) {
// Check if the binary exists at the given path
fs.access(binaryPath, fs.constants.X_OK, (err) => {
callback(!err); // true if binary exists and is executable
});
} else {
callback(false); // No output from the command
}
})
}