2023-05-20 02:08:25 +00:00
|
|
|
import process from 'node:process';
|
|
|
|
|
import * as dotenv from 'dotenv';
|
2024-02-08 01:39:34 +00:00
|
|
|
// import chalk from 'chalk';
|
2022-12-31 15:21:57 +00:00
|
|
|
import { createServer } from 'vite';
|
2023-05-06 00:28:15 +00:00
|
|
|
import pluginReact from '@vitejs/plugin-react';
|
2022-12-31 15:21:57 +00:00
|
|
|
import type { UserConfig } from 'vite';
|
2022-12-31 15:29:45 +00:00
|
|
|
import { joinPackagePath } from './util/project';
|
2022-12-31 15:21:57 +00:00
|
|
|
|
2023-05-20 02:08:25 +00:00
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
|
|
const pkgName = process.env.DEV_IDRAW_MODULE || 'idraw';
|
2024-02-08 01:39:34 +00:00
|
|
|
console.log(`Dev package [${pkgName}]`);
|
2023-05-20 02:08:25 +00:00
|
|
|
|
|
|
|
|
const openPage = '/dev/index.html';
|
2022-12-31 15:21:57 +00:00
|
|
|
|
|
|
|
|
async function dev() {
|
2023-02-11 11:12:58 +00:00
|
|
|
const viteConfig = getViteConfig();
|
2022-12-31 15:21:57 +00:00
|
|
|
const server = await createServer({
|
|
|
|
|
configFile: false,
|
|
|
|
|
...viteConfig
|
|
|
|
|
});
|
|
|
|
|
await server.listen();
|
|
|
|
|
server.printUrls();
|
|
|
|
|
const { port, host = '127.0.0.1' } = server.config?.server || {};
|
2023-05-20 02:08:25 +00:00
|
|
|
|
2024-02-08 01:39:34 +00:00
|
|
|
console.log(`Open: ` + `http://${host}:${port}${openPage}`);
|
2022-12-31 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-11 11:12:58 +00:00
|
|
|
function getViteConfig(): UserConfig {
|
2022-12-31 15:21:57 +00:00
|
|
|
const viteConfig: UserConfig = {
|
2022-12-31 15:29:45 +00:00
|
|
|
root: joinPackagePath(pkgName),
|
2024-06-02 05:20:30 +00:00
|
|
|
publicDir: joinPackagePath(pkgName, 'dev'),
|
2022-12-31 15:21:57 +00:00
|
|
|
server: {
|
|
|
|
|
port: 8080,
|
2023-05-20 02:08:25 +00:00
|
|
|
host: '127.0.0.1',
|
|
|
|
|
open: openPage
|
2022-12-31 15:21:57 +00:00
|
|
|
},
|
2023-05-06 00:28:15 +00:00
|
|
|
plugins: [pluginReact()],
|
2023-02-11 11:12:58 +00:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@idraw/types': joinPackagePath('types', 'src', 'index.ts'),
|
|
|
|
|
'@idraw/util': joinPackagePath('util', 'src', 'index.ts'),
|
|
|
|
|
'@idraw/renderer': joinPackagePath('renderer', 'src', 'index.ts'),
|
|
|
|
|
'@idraw/board': joinPackagePath('board', 'src', 'index.ts'),
|
|
|
|
|
'@idraw/core': joinPackagePath('core', 'src', 'index.ts')
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-12-31 15:21:57 +00:00
|
|
|
esbuild: {
|
2023-05-06 00:28:15 +00:00
|
|
|
include: [/\.(ts|tsx|js|jsx)$/],
|
2022-12-31 15:21:57 +00:00
|
|
|
exclude: [/\.html$/]
|
|
|
|
|
},
|
|
|
|
|
optimizeDeps: {}
|
|
|
|
|
};
|
|
|
|
|
return viteConfig;
|
|
|
|
|
}
|
2023-05-20 02:08:25 +00:00
|
|
|
|
|
|
|
|
dev();
|