generated from League-of-Foundry-Developers/foundry-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
140 lines (133 loc) · 3.97 KB
/
vite.config.ts
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import * as fsPromises from 'fs/promises';
import copy from 'rollup-plugin-copy';
import scss from 'rollup-plugin-scss';
import {defineConfig, Plugin} from 'vite';
import {resolve as pathResolve} from 'path';
import checker from 'vite-plugin-checker';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import './src/styles/module.css';
import './src/styles/styles.css';
// const path = require('path');
const moduleVersion = process.env.MODULE_VERSION;
const githubProject = 'MoonIsFalling/pf2e-display-actions';
const projectName = 'pf2e-display-actions';
// const githubTag = process.env.GH_TAG;
console.log(process.env.VSCODE_INJECTION);
const config = defineConfig({
root: 'src/',
base: `/modules/${projectName}/`,
// publicDir: path.pathResolve(__dirname, 'public'),
publicDir: pathResolve(__dirname, 'public'),
server: {
port: 30001,
open: true,
proxy: {
'^(?!/modules/pf2e-display-actions)': 'http://localhost:30000/',
'/socket.io': {
target: 'ws://localhost:30000',
ws: true,
},
},
},
resolve: {
alias: [
{
find: './runtimeConfig',
replacement: './runtimeConfig.browser',
},
],
},
// optimizeDeps: {
// // exclude: ['@sveltejs/vite-plugin-svelte'],
// include: ['jszip'],
// },
build: {
// outDir: path.pathResolve(__dirname, 'dist'),
outDir: pathResolve(__dirname, 'dist'),
sourcemap: true,
emptyOutDir: true,
reportCompressedSize: true,
minify: 'terser',
terserOptions: {
mangle: true,
keep_classnames: true,
keep_fnames: true,
compress: true,
},
lib: {
name: projectName,
// entry: path.pathResolve(__dirname, 'src/ts/module.ts'),
entry: pathResolve(__dirname, 'src/ts/module.ts'),
formats: ['es'],
fileName: 'scripts/module',
},
rollupOptions: {
input: {
index: pathResolve(__dirname, 'src/ts/module.ts'),
},
treeshake: true,
preserveEntrySignatures: 'strict',
output: {
// generatedCode: 'es5',
// extend: true,
// preserveModules: true,
// dynamicImportInCjs: true,
// externalImportAssertions: true,
esModule: true,
// file: path.resolve(__dirname, 'dist/scripts/module.js'),
// file: resolve(__dirname, 'dist/scripts/module.js'),
dir: 'dist',
},
},
},
plugins: [
resolve(),
commonjs({
transformMixedEsModules: true,
}),
updateModuleManifestPlugin(),
checker({
typescript: true,
}),
scss({
fileName: 'style.css',
// output: 'dist/style.css',
includePaths: ['styles/module.css', 'styles/styles.css'],
sourceMap: true,
watch: ['src/styles/*.scss'],
}),
copy({
targets: [
{src: 'src/languages', dest: 'dist'},
{src: 'src/templates', dest: 'dist'},
{src: 'src/images', dest: 'dist'},
],
hook: 'writeBundle',
}),
],
});
function updateModuleManifestPlugin(): Plugin {
return {
name: 'update-module-manifest',
async writeBundle(): Promise<void> {
const packageContents = JSON.parse(await fsPromises.readFile('./package.json', 'utf-8')) as Record<
string,
unknown
>;
const version = moduleVersion || (packageContents.version as string);
const manifestContents: string = await fsPromises.readFile('src/module.json', 'utf-8');
const manifestJson = JSON.parse(manifestContents) as Record<string, unknown>;
manifestJson['version'] = version;
if (githubProject) {
const baseUrl = `https://github.com/${githubProject}/releases`;
manifestJson['manifest'] = `${baseUrl}/download/${version}/module.json`;
if (version) {
manifestJson['download'] = `${baseUrl}/download/${version}/module.zip`;
}
}
await fsPromises.writeFile('dist/module.json', JSON.stringify(manifestJson, null, 4));
},
};
}
export default config;