-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.js
45 lines (41 loc) · 1.36 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
import { spawnSync } from "child_process";
import { defineConfig } from "vite";
// Detect whether Vite runs in development or production mode
function isDev() {
return process.env.NODE_ENV !== "production";
}
// Utility to invoke a given sbt task and fetch its output
function printSbtTask(task) {
const args = ["--error", `print ${task}`];
const options = {
stdio: [
"pipe", // StdIn
"pipe", // StdOut
"inherit", // StdErr
],
};
const result = process.platform === 'win32'
? spawnSync("sbt.bat", args.map(x => `"${x}"`), {shell: true, ...options})
: spawnSync("sbt", args, options);
const output = result.stdout.toString('utf8').trim().split("\n")
console.log("Scala JS Output path: " + output[output.length - 1])
if (result.error)
throw result.error;
if (result.status !== 0)
throw new Error(`sbt process failed with exit code ${result.status}`);
return output[output.length - 1].trim();
}
// Get the output of fastLinkJS or fullLinkJS depending on isDev()
const scalaJSOutputTask = isDev() ? "fastLinkJSOutput" : "fullLinkJSOutput";
const scalaJSOutput = printSbtTask(scalaJSOutputTask);
// Tell Vite to replace references to `@scalaJSOutput` by the path computed above
export default defineConfig({
resolve: {
alias: [
{
find: "@scalaJSOutput",
replacement: scalaJSOutput,
},
],
},
});