Skip to content
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

implement build #3

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions bin/auto-reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,44 @@

import path from 'node:path';
import { fileURLToPath } from 'url';
import { createServer } from 'vite';
import { createServer, build } from 'vite';
import { ViteEjsPlugin as viteEjsPlugin } from 'vite-plugin-ejs';
import { getTheme, getTitle } from '../lib/utils.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const argv = process.argv.slice(2);
const cwd = process.cwd();

getTheme();
const themeFolder = path.dirname(getTheme());
const config = {
configFile: false,
root: path.join(__dirname, '..', 'src'),
publicDir: path.join(cwd, 'public'),
server: {
port: 1337,
fs: {
allow: [themeFolder, '.']
}
},
plugins: [
viteEjsPlugin({
title: getTitle(),
}),
],
resolve: {
alias: {
slides: path.join(cwd, 'slides'),
'@theme': themeFolder,
},
},
build: {
outDir: path.join(cwd, 'dist')
}
};

async function start() {
const themeFolder = path.dirname(getTheme());
const server = await createServer({
configFile: false,
root: path.join(__dirname, '..', 'src'),
server: {
port: 1337,
fs: {
allow: [themeFolder, '.']
}
},
plugins: [
viteEjsPlugin({
title: getTitle(),
}),
],
resolve: {
alias: {
slides: path.join(cwd, 'slides'),
'@theme': themeFolder,
},
},
});

const server = await createServer(config);

server.watcher.add(path.join(cwd, 'slides'));

Expand All @@ -43,10 +48,8 @@ async function start() {
server.bindCLIShortcuts({ print: true });
}

async function build() {}

if (!argv[0] || argv[0] === 'start') {
start();
} else if (argv[0] === 'build') {
// Build for production
build(config)
}