Handle base urls nicely
This commit is contained in:
parent
b7db1dfdb3
commit
bfcad7a7c7
2
.github/workflows/build.yaml
vendored
2
.github/workflows/build.yaml
vendored
|
@ -19,7 +19,7 @@ jobs:
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: nix build
|
run: nix build .#erratic-gate-github-pages
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v2
|
uses: actions/upload-pages-artifact@v2
|
||||||
|
|
70
build.js
70
build.js
|
@ -4,41 +4,49 @@ import { sassPlugin } from 'esbuild-sass-plugin'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
|
||||||
const serve = process.env.ESBUILD_SERVE === '1'
|
const serve = process.env.ESBUILD_SERVE === '1'
|
||||||
|
const baseurl = process.env.ESBUILD_BASEURL
|
||||||
|
|
||||||
|
console.log(`Building with baseurl ${baseurl}`)
|
||||||
|
|
||||||
const ctx = await esbuild.context({
|
const ctx = await esbuild.context({
|
||||||
entryPoints: ['src/index.ts'],
|
entryPoints: ['src/index.ts'],
|
||||||
minify: !serve,
|
minify: !serve,
|
||||||
bundle: true,
|
bundle: true,
|
||||||
metafile: true,
|
metafile: true,
|
||||||
splitting: true,
|
splitting: true,
|
||||||
outdir: 'dist',
|
outdir: 'dist',
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
target: ['es2020'],
|
target: ['es2020'],
|
||||||
assetNames: 'assets/[name]-[hash]',
|
assetNames: 'assets/[name]-[hash]',
|
||||||
loader: {
|
loader: {
|
||||||
'.svg': 'file'
|
'.svg': 'file'
|
||||||
},
|
},
|
||||||
plugins: [
|
define: {
|
||||||
htmlPlugin({
|
'process.env.BASEURL': JSON.stringify(baseurl)
|
||||||
files: [
|
},
|
||||||
{
|
plugins: [
|
||||||
filename: 'index.html',
|
htmlPlugin({
|
||||||
entryPoints: ['src/index.ts'],
|
files: [
|
||||||
favicon: 'public/favicon.ico',
|
{
|
||||||
htmlTemplate: 'public/index.html',
|
filename: 'index.html',
|
||||||
scriptLoading: 'module'
|
entryPoints: ['src/index.ts'],
|
||||||
}
|
favicon: 'public/favicon.ico',
|
||||||
]
|
htmlTemplate: 'public/index.html',
|
||||||
}),
|
scriptLoading: 'module'
|
||||||
sassPlugin({})
|
}
|
||||||
]
|
]
|
||||||
|
}),
|
||||||
|
sassPlugin({})
|
||||||
|
],
|
||||||
|
publicPath: baseurl
|
||||||
})
|
})
|
||||||
|
|
||||||
if (serve) {
|
if (serve) {
|
||||||
const { port, host } = await ctx.serve({ servedir: 'dist' })
|
const { port, host } = await ctx.serve({ servedir: 'dist' })
|
||||||
console.log(`Serving on ${host}:${port}`)
|
console.log(`Serving on ${host}:${port}`)
|
||||||
} else {
|
} else {
|
||||||
await ctx.rebuild()
|
await ctx.rebuild()
|
||||||
await ctx.dispose()
|
await ctx.dispose()
|
||||||
fs.cpSync('./dist/index.html', './dist/404.html') // Needed to please github pages
|
fs.cpSync('./dist/index.html', './dist/404.html') // Needed to please github pages
|
||||||
|
console.log(`Project bundled successfully`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,18 @@
|
||||||
src = pkgs.lib.cleanSource ./.;
|
src = pkgs.lib.cleanSource ./.;
|
||||||
npmDepsHash = "sha256-f5mw6IjkhZgsIuzCz9d7DvoAdceY1y+yWXn1BOonsVI=";
|
npmDepsHash = "sha256-f5mw6IjkhZgsIuzCz9d7DvoAdceY1y+yWXn1BOonsVI=";
|
||||||
|
|
||||||
|
ESBUILD_BASEURL = "";
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
cp -r dist $out/www
|
cp -r dist $out/www
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
packages.erratic-gate-github-pages = packages.erratic-gate.overrideAttrs {
|
||||||
|
ESBUILD_BASEURL = "/erratic-gate";
|
||||||
|
};
|
||||||
|
|
||||||
packages.default = packages.erratic-gate;
|
packages.default = packages.erratic-gate;
|
||||||
|
|
||||||
devShells.default =
|
devShells.default =
|
||||||
|
|
|
@ -17,36 +17,36 @@ import { loadSubject } from '../subjects/loadedSubject'
|
||||||
import LogicGateInfoPage from '../../logic-gate-info/components/LogicGateInfoPage'
|
import LogicGateInfoPage from '../../logic-gate-info/components/LogicGateInfoPage'
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadSubject.next(true)
|
loadSubject.next(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
|
|
||||||
<Theme theme={muiTheme}>
|
<Theme theme={muiTheme}>
|
||||||
<BrowserRouter>
|
<BrowserRouter basename={process.env.BASEURL}>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
|
|
||||||
<Route path="/" component={Root} exact />
|
<Route path="/" component={Root} exact />
|
||||||
<Route path="/gates" component={LogicGatePage} />
|
<Route path="/gates" component={LogicGatePage} />
|
||||||
<Route path="/info/:name" component={LogicGateInfoPage} />
|
<Route path="/info/:name" component={LogicGateInfoPage} />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</Theme>
|
</Theme>
|
||||||
|
|
||||||
<ToastContainer
|
<ToastContainer
|
||||||
position="top-left"
|
position="top-left"
|
||||||
autoClose={5000}
|
autoClose={5000}
|
||||||
hideProgressBar={false}
|
hideProgressBar={false}
|
||||||
newestOnTop={false}
|
newestOnTop={false}
|
||||||
closeOnClick
|
closeOnClick
|
||||||
rtl={false}
|
rtl={false}
|
||||||
draggable
|
draggable
|
||||||
pauseOnHover
|
pauseOnHover
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App
|
export default App
|
||||||
|
|
Loading…
Reference in a new issue