-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript? #4
Comments
Here is my example config: import fs from 'fs/promises';
import path from 'path';
import vitePluginElectron from 'vite-plugin-electron/simple';
import type { AstroIntegration, AstroConfig, RouteData } from 'astro';
import type { UserConfig as ViteUserConfig } from 'vite';
interface ElectronIntegrationConfig {
main?: {
entry?: string;
vite?: Partial<ViteUserConfig>;
};
preload?: {
input?: string;
vite?: Partial<ViteUserConfig>;
};
renderer?: Partial<ViteUserConfig>;
}
export default (
integrationConfig: ElectronIntegrationConfig = {},
): AstroIntegration => ({
name: 'astro-electron',
hooks: {
'astro:config:setup': ({
config,
command,
updateConfig,
}: {
config: AstroConfig;
command: string;
updateConfig: (newConfig: Partial<AstroConfig>) => void;
}) => {
if (command === 'build') {
updateConfig({
base: '/',
});
}
// Add Vite plugin for Electron
updateConfig({
vite: {
plugins: [
vitePluginElectron({
main: {
entry: integrationConfig?.main?.entry || 'src/electron/main.ts',
vite: integrationConfig?.main?.vite || config.vite,
},
preload: {
input:
integrationConfig?.preload?.input ||
'src/electron/preload.ts',
vite: integrationConfig?.preload?.vite || config.vite,
},
renderer: integrationConfig?.renderer || undefined,
}),
],
},
});
},
'astro:build:done': async ({
dir,
routes,
}: {
dir: URL;
routes: RouteData[];
// ... other properties
}) => {
await Promise.all(
routes.map(async (route) => {
if (route.distURL) {
const filePath = new URL(route.distURL).pathname;
const file = await fs.readFile(filePath, 'utf-8');
const localDir = path.dirname(filePath);
const relativePath = path.relative(localDir, new URL(dir).pathname);
await fs.writeFile(
route.distURL,
file.replaceAll(
/\/(astro-electron|public)/g,
relativePath || '.',
),
);
}
}),
);
},
},
}); |
Hey, that's a good idea, can you make a PR that will handle all the necessary changes? |
Yeah sure! #5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice to convert to typescript so both ts and js can work. Currently using TypeScript in a project.
The text was updated successfully, but these errors were encountered: