Skip to content

Commit

Permalink
fix: non-webxdc build not working
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Apr 3, 2023
1 parent 4ee8ceb commit e285fa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 1 addition & 3 deletions index.html
Expand Up @@ -16,9 +16,7 @@
<strong>We're sorry but Vikunja doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- TODO_OFFLINE maybe need to dynamically import it instead.
Not sure if it works ok inside Delta Chat. -->
<script type="module" src="/webxdc.js"></script>
<!--WEBXDC_SCRIPT_PLACEHOLDER-->
<script type="module" src="/src/main.ts"></script>
<script>
//
Expand Down
20 changes: 17 additions & 3 deletions vite.config.ts
Expand Up @@ -34,6 +34,22 @@ console.log(isModernBuild
: 'Building "legacy" build with "@vitejs/plugin-legacy"',
)

// Very hacky. Why not incldue it right there in `index.html`? Because otherwise
// would try to resolve `webxdc.js` and transform it.
// TODO_OFFLINE refactor: don't include it in non-webxdc build because it's always a 404.
const injectWebxdcIntoIndexHtmlPlugin = () => {
return {
name: 'inject-webxdc-into-index-html',
enforce: 'post',
transformIndexHtml(html) {
return html.replace(
'<!--WEBXDC_SCRIPT_PLACEHOLDER-->',
'<script type="module" src="/webxdc.js"></script>'
)
},
}
}

/**
* @param fontNames Array of the file names of the fonts without axis and hash suffixes
*/
Expand Down Expand Up @@ -87,6 +103,7 @@ export default defineConfig(({mode}) => {
},
},
plugins: [
injectWebxdcIntoIndexHtmlPlugin(),
vue({
reactivityTransform: true,
}),
Expand Down Expand Up @@ -187,9 +204,6 @@ export default defineConfig(({mode}) => {
build: {
target: 'esnext',
rollupOptions: {
external: [
"/webxdc.js"
],
plugins: [
visualizer({
filename: 'stats.html',
Expand Down

0 comments on commit e285fa9

Please sign in to comment.