-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.js
75 lines (68 loc) · 1.96 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
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import { VitePWA } from 'vite-plugin-pwa';
import { createHtmlPlugin } from 'vite-plugin-html';
import { viteSingleFile } from 'vite-plugin-singlefile';
import { compileInk, watchInkFiles } from './vite/ink-compiler-plugin';
import { removeInkFilesFromBuild } from './vite/remove-ink-files-plugin';
import getPWAConfig from './vite/pwa-config';
import atramentCfg from './atrament.config.json';
export default defineConfig(({ mode }) => {
const inkCompileFormat = atramentCfg.game.format || (mode === 'singlefile' ? 'js' : 'json');
const plugins = [
preact(),
createHtmlPlugin({
inject: {
data: {
title: atramentCfg.name,
description: atramentCfg.description
},
},
}),
watchInkFiles(inkCompileFormat),
compileInk(inkCompileFormat),
removeInkFilesFromBuild(),
]
let buildDir = 'build';
if (mode === 'singlefile') {
plugins.push(viteSingleFile());
buildDir = 'build_singlefile';
} else if (mode === 'production') {
plugins.push(VitePWA(getPWAConfig(atramentCfg)));
}
return {
plugins,
define: {
__INK_SCRIPT__: JSON.stringify(`${atramentCfg.game.source}.${inkCompileFormat}`)
},
resolve: {
alias: [
{ find: 'src', replacement: "/src" },
{ find: 'inkjs', replacement: '/node_modules/inkjs/dist/ink.mjs' }
],
},
server: {
port: 8900
},
build: {
outDir: buildDir
},
publicDir: 'root',
base: './',
experimental: {
renderBuiltUrl(filename, { type, hostType }) {
if (type === 'asset') {
if (hostType === 'html') {
// apply "base: './'" to HTML template
return `./${filename}`;
}
if (hostType === 'css') {
// fix issue with CSS fonts
return filename.replace('assets/','');
}
}
return filename;
},
},
};
});