Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Fix asset loading for production build
Hakan Shehue1ff6440cf27
diff --git a/desktop/assets/neotrax.otf b/desktop/assets/fonts/neotrax.otfsimilarity index 100%rename from desktop/assets/neotrax.otfrename to desktop/assets/fonts/neotrax.otfdiff --git a/desktop/assets/icons.svg b/desktop/assets/icons/sprite.svgsimilarity index 100%rename from desktop/assets/icons.svgrename to desktop/assets/icons/sprite.svgdiff --git a/desktop/forge.config.ts b/desktop/forge.config.tsindex 1ab9f7e9..36dc75e1 100644--- a/desktop/forge.config.ts+++ b/desktop/forge.config.ts@@ -10,9 +10,28 @@ import { FuseV1Options, FuseVersion } from '@electron/fuses';const config: ForgeConfig = {packagerConfig: {asar: true,+ ignore: [+ /^\/src/,+ /^\/test/,+ /^\/tools/,+ /^\/release/,+ /^\/docs/,+ /\.git/,+ /\.vscode/,+ /\.idea/,+ /^\/\.env/,+ // Don't ignore node_modules+ // /^\/node_modules/+ ],+ extraResource: ['assets'],},rebuildConfig: {},- makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],+ makers: [+ new MakerSquirrel({}),+ new MakerZIP({}, ['darwin']),+ new MakerRpm({}),+ new MakerDeb({}),+ ],plugins: [new VitePlugin({// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.diff --git a/desktop/index.html b/desktop/index.htmlindex c18ba997..ad89e1b2 100644--- a/desktop/index.html+++ b/desktop/index.html@@ -5,7 +5,7 @@<title>Neuron</title><metahttp-equiv="Content-Security-Policy"- content="script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: avatar: local-file:; "+ content="default-src 'self' 'unsafe-inline' data: avatar: local-file: asset:;"/></head><body>diff --git a/desktop/src/lib/emojis.ts b/desktop/src/lib/emojis.tsindex c4b0ba34..41c838a8 100644--- a/desktop/src/lib/emojis.ts+++ b/desktop/src/lib/emojis.ts@@ -30,7 +30,7 @@ export const getEmojiById = (id: string): Emoji | undefined => {};export const getEmojiUrl = (id: string): string => {- return `/assets/emojis/${id}.svg`;+ return `asset://emojis/${id}.svg`;};export const searchEmojis = (query: string): Emoji[] => {diff --git a/desktop/src/lib/icons.ts b/desktop/src/lib/icons.tsindex 8f32fdd2..f53d2b19 100644--- a/desktop/src/lib/icons.ts+++ b/desktop/src/lib/icons.ts@@ -17,7 +17,7 @@ type IconPickerEmojiRow = {};export const getIconUrl = (id: string): string => {- return `/assets/icons/${id}.svg`;+ return `asset://icons/${id}.svg`;};export const searchIcons = (query: string): Icon[] => {diff --git a/desktop/src/main.ts b/desktop/src/main.tsindex c4d0d726..2271caf6 100644--- a/desktop/src/main.ts+++ b/desktop/src/main.ts@@ -1,4 +1,4 @@-import { app, ipcMain, BrowserWindow, protocol, dialog } from 'electron';+import { app, ipcMain, BrowserWindow, protocol, dialog, net } from 'electron';import path from 'path';import { eventBus } from '@/lib/event-bus';import { MutationInput, MutationMap } from '@/operations/mutations';@@ -53,6 +53,20 @@ const createWindow = async () => {protocol.handle('local-file', (request) => {return fileManager.handleFileRequest(request);});++ protocol.handle('asset', (request) => {+ const url = request.url.replace('asset://', '');+ if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {+ return net.fetch(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}/assets/${url}`);+ }++ const localFileUrl = `file://${path.join(+ process.resourcesPath,+ 'assets',+ url,+ )}`;+ return net.fetch(localFileUrl);+ });};// This method will be called when Electron has finisheddiff --git a/desktop/src/renderer/components/ui/icon.tsx b/desktop/src/renderer/components/ui/icon.tsxindex e0d8244c..cffbe4d8 100644--- a/desktop/src/renderer/components/ui/icon.tsx+++ b/desktop/src/renderer/components/ui/icon.tsx@@ -18,7 +18,7 @@ const Icon = React.forwardRef<SVGSVGElement, IconProps>((props, ref) => {width={computedSize}{...props}>- <use xlinkHref={`/assets/icons.svg#ri-${props.name}`} />+ <use href={`asset://icons/sprite.svg#ri-${props.name}`} /></svg>);});diff --git a/desktop/src/renderer/styles/index.css b/desktop/src/renderer/styles/index.cssindex b4a445ad..a9158e7f 100644--- a/desktop/src/renderer/styles/index.css+++ b/desktop/src/renderer/styles/index.css@@ -86,7 +86,7 @@@font-face {font-family: 'neotrax';- src: url('/assets/neotrax.otf') format('truetype');+ src: url('asset://fonts/neotrax.otf') format('truetype');font-weight: normal;font-style: normal;}