Skip to content

Commit

Permalink
Implement it.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Feb 16, 2024
1 parent f4f6092 commit 003e013
Show file tree
Hide file tree
Showing 14 changed files with 1,093 additions and 56 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
on:
push:
pull_request:

name: CI
jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Install and build
run: |
npm ci
npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

deploy:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Disable Jekyll
run: |
touch dist/.nojekyll
- name: Publish artifact
if: "${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' }}"
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
folder: dist/
55 changes: 55 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as process from 'node:process';
import * as esbuild from 'esbuild';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

const mode = (process.argv[2] ?? 'build');
const options = {
logLevel: 'info',
plugins: [metaUrlPlugin()],
bundle: true,
loader: {
'.html': 'copy',
'.svg': 'dataurl',
'.ttf': 'file',
'.woff': 'file',
'.woff2': 'file',
'.json': 'file',
'.wasm': 'file',
'.asm.wasm': 'copy',
'.zip': 'file',
},
external: [
'fs/promises', // @yowasp/yosys
'node-fetch', // pyodide
],
define: {
'globalThis.IS_PRODUCTION': (mode === 'minify' ? 'true' : 'false'),
},
target: 'es2021',
format: 'esm',
sourcemap: 'linked',
minify: (mode === 'minify'),
outdir: 'dist',
entryPoints: {
'index': './src/index.html',
'app': './src/app.tsx',
'app.worker': './src/worker.ts',
'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js',
'pyodide.asm': 'pyodide/pyodide.asm.wasm',
},
};

if (mode === 'build' || mode === 'minify') {
await esbuild.build(options);
} else if (mode === 'watch') {
const context = await esbuild.context(options);
await context.watch();
} else if (mode === 'serve') {
const context = await esbuild.context(options);
await context.rebuild();
await context.watch();
// Specifying `servedir` is necessary for files built by meta URL plugin to be accessible.
await context.serve({ servedir: 'dist' });
} else {
console.error(`Usage: ${process.argv0} [build|watch|serve|minify]`);
}
Loading

0 comments on commit 003e013

Please sign in to comment.