-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.dev.js
45 lines (37 loc) · 1.48 KB
/
build.dev.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 { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dappPackagePath } from './build.config.local.mjs';
const distDir = './dist';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 1. Build with Vite
execSync('vite build', { stdio: 'inherit' });
// 2. Copy package.json to dist
fs.copyFileSync(
path.resolve(__dirname, 'package.json'),
path.resolve(__dirname, distDir, 'package.json')
);
// 3. Clean target dir
fs.readdirSync(dappPackagePath).forEach(file => {
const fullPath = path.join(dappPackagePath, file);
if (fs.lstatSync(fullPath).isFile() && ['.js', '.css'].includes(path.extname(file)) || file === 'package.json') {
fs.rmSync(fullPath, { force: true });
} else if (fs.lstatSync(fullPath).isDirectory() && file === 'iconfonts') {
fs.rmSync(fullPath, { recursive: true, force: true });
}
});
// 4. Copy dist files
fs.readdirSync(distDir).forEach(file => {
const src = path.join(distDir, file);
const dest = path.join(dappPackagePath, file);
if (fs.lstatSync(src).isDirectory()) {
fs.cpSync(src, dest, { recursive: true });
} else {
fs.copyFileSync(src, dest);
}
});
console.log('✅ Build and copy complete (ESM mode).');