feat: bootloader in frontend package (frontend)
This commit is contained in:
parent
4c41930554
commit
af011562bd
|
@ -185,6 +185,7 @@ export type Config = {
|
|||
driveUrl: string;
|
||||
userAgent: string;
|
||||
frontendEntry: { file: string | null };
|
||||
frontendBootLoader: { file: string };
|
||||
frontendManifestExists: boolean;
|
||||
frontendEmbedEntry: { file: string | null };
|
||||
frontendEmbedManifestExists: boolean;
|
||||
|
@ -235,7 +236,7 @@ export function loadConfig(): Config {
|
|||
const frontendEmbedManifestExists = fs.existsSync(_dirname + '/../../../built/_frontend_embed_vite_/manifest.json');
|
||||
const frontendManifest = frontendManifestExists ?
|
||||
JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_frontend_vite_/manifest.json`, 'utf-8'))
|
||||
: { 'src/_boot_.ts': { file: null } };
|
||||
: { 'src/_boot_.ts': { file: null }, 'src/_bootloader.ts': { file: 'src/_bootloader.ts' } };
|
||||
const frontendEmbedManifest = frontendEmbedManifestExists ?
|
||||
JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_frontend_embed_vite_/manifest.json`, 'utf-8'))
|
||||
: { 'src/boot.ts': { file: null } };
|
||||
|
@ -312,6 +313,7 @@ export function loadConfig(): Config {
|
|||
: null,
|
||||
userAgent: `Misskey/${version} (${config.url})`,
|
||||
frontendEntry: frontendManifest['src/_boot_.ts'],
|
||||
frontendBootLoader: frontendManifest['src/_bootloader.ts'],
|
||||
frontendManifestExists: frontendManifestExists,
|
||||
frontendEmbedEntry: frontendEmbedManifest['src/boot.ts'],
|
||||
frontendEmbedManifestExists: frontendEmbedManifestExists,
|
||||
|
|
|
@ -2,6 +2,7 @@ block vars
|
|||
|
||||
block loadClientEntry
|
||||
- const entry = config.frontendEntry;
|
||||
- const bootLoader = config.frontendBootLoader;
|
||||
- const baseUrl = config.url;
|
||||
|
||||
doctype html
|
||||
|
@ -76,8 +77,7 @@ html
|
|||
script(type='application/json' id='misskey_clientCtx' data-generated-at=now)
|
||||
!= clientCtx
|
||||
|
||||
script
|
||||
include ../boot.js
|
||||
script(type='module', src=`/vite/${bootLoader.file}`)
|
||||
|
||||
body
|
||||
noscript: p
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
type FIXME = any;
|
||||
|
||||
declare const _LANGS_: string[][];
|
||||
declare const _LANG_IDS_: string[];
|
||||
declare const _VERSION_: string;
|
||||
declare const _ENV_: string;
|
||||
declare const _DEV_: boolean;
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
interface Window {
|
||||
CLIENT_ENTRY: string | undefined;
|
||||
}
|
||||
|
||||
// ブロックの中に入れないと、定義した変数がブラウザのグローバルスコープに登録されてしまい邪魔なので
|
||||
(async () => {
|
||||
const CLIENT_ENTRY = window.CLIENT_ENTRY;
|
||||
|
||||
window.onerror = (e) => {
|
||||
console.error(e);
|
||||
renderError('SOMETHING_HAPPENED', e);
|
||||
|
@ -23,7 +29,7 @@
|
|||
}
|
||||
|
||||
//#region Detect language
|
||||
const supportedLangs = LANGS;
|
||||
const supportedLangs = _LANG_IDS_;
|
||||
/** @type { string } */
|
||||
let lang = localStorage.getItem('lang');
|
||||
if (lang == null || !supportedLangs.includes(lang)) {
|
||||
|
@ -46,7 +52,7 @@
|
|||
|
||||
//#region Script
|
||||
async function importAppScript() {
|
||||
await import(CLIENT_ENTRY ? `/vite/${CLIENT_ENTRY.replace('scripts', lang)}` : '/vite/src/_boot_.ts')
|
||||
await import(`/vite/${(CLIENT_ENTRY ?? 'src/_boot_.ts').replace('scripts', lang)}`)
|
||||
.catch(async e => {
|
||||
console.error(e);
|
||||
renderError('APP_IMPORT', e);
|
|
@ -25,3 +25,8 @@ declare module 'search-index:settings' {
|
|||
declare module 'search-index:admin' {
|
||||
export const searchIndexes: XGeneratedSearchIndexItem[];
|
||||
}
|
||||
|
||||
declare module 'virtual:supported-langs' {
|
||||
const value: string[];
|
||||
export default value;
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ export function getConfig(): UserConfig {
|
|||
define: {
|
||||
_VERSION_: JSON.stringify(meta.version),
|
||||
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])),
|
||||
_LANG_IDS_: JSON.stringify(Object.keys(locales)),
|
||||
_ENV_: JSON.stringify(process.env.NODE_ENV),
|
||||
_DEV_: process.env.NODE_ENV !== 'production',
|
||||
_PERF_PREFIX_: JSON.stringify('Misskey:'),
|
||||
|
@ -178,6 +179,7 @@ export function getConfig(): UserConfig {
|
|||
input: {
|
||||
i18n: './src/i18n.ts',
|
||||
entry: './src/_boot_.ts',
|
||||
bootloader: './src/_bootloader.ts',
|
||||
},
|
||||
external: externalPackages.map(p => p.match),
|
||||
preserveEntrySignatures: 'allow-extension',
|
||||
|
|
|
@ -53,7 +53,7 @@ async function buildBackendScript() {
|
|||
await fs.mkdir('./packages/backend/built/server/web', { recursive: true });
|
||||
|
||||
for (const file of [
|
||||
'./packages/backend/src/server/web/boot.js',
|
||||
//'./packages/backend/src/server/web/boot.js',
|
||||
'./packages/backend/src/server/web/boot.embed.js',
|
||||
'./packages/backend/src/server/web/bios.js',
|
||||
'./packages/backend/src/server/web/cli.js',
|
||||
|
|
Loading…
Reference in New Issue