forked from Robbendebiene/Gesturefy
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.ts
More file actions
77 lines (68 loc) · 2.29 KB
/
Copy pathbuild.ts
File metadata and controls
77 lines (68 loc) · 2.29 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
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
// https://github.com/rollup/rollup/issues/2756
// https://github.com/rollup/rollup/issues/5601
import { access, rm } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { build } from 'vite';
const SrcDirname = 'src';
const DistDirname = 'dist';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const srcPath = resolve(__dirname, SrcDirname);
const distPath = resolve(__dirname, DistDirname);
interface EntryPoint {
inputName: string;
inputPath: string;
outputDirname?: string;
}
const entryPoints: EntryPoint[] = [
{ inputName: 'background', inputPath: resolve(srcPath, 'core/background.ts') },
{ inputName: 'content', inputPath: resolve(srcPath, 'core/content.ts') },
{ inputName: 'options', inputPath: resolve(srcPath, 'options/index.html'), outputDirname: 'options' },
{
inputName: 'popup-command',
inputPath: resolve(srcPath, 'core/view/iframe-popup-command.html'),
outputDirname: 'core/view',
},
// { inputName: 'inject', inputPath: resolve(srcPath, 'inject/index.ts') },
// { inputName: 'popup', inputPath: resolve(srcPath, 'popup/index.html'), outputDirname: 'popup' },
];
const isWatch = process.argv.some(arg => arg.includes('--watch'));
function createConfig(entry: EntryPoint) {
return {
root: `${SrcDirname}${entry.outputDirname ? `/${entry.outputDirname}` : ''}`,
base: './',
resolve: {
tsconfigPaths: true
},
build: {
watch: isWatch ? {} : undefined,
minify: isWatch ? false : true,
rollupOptions: {
input: { [entry.inputName]: entry.inputPath },
output: {
inlineDynamicImports: true,
entryFileNames: '[name].bundle.js',
chunkFileNames: '[name].chunk.js',
assetFileNames: '[name][extname]',
},
},
outDir: `${distPath}${entry.outputDirname ? `/${entry.outputDirname}` : ''}`,
},
publicDir: 'static',
};
}
async function start() {
try {
await access(distPath);
await rm(distPath, { recursive: true, force: true });
} catch {
// let it be
}
for (const entry of entryPoints) {
console.log(`Building ${entry.inputName}...`);
await build(createConfig(entry));
}
console.log('All builds finished.');
}
await start();