-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
233 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useHead } from '@vueuse/head' | ||
|
||
/* __imports__ */ | ||
|
||
export default function setupHead() { | ||
useHead({ | ||
title: 'Slidev', | ||
link: [ | ||
{ rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }, | ||
], | ||
}) | ||
|
||
/* __injections__ */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,60 @@ | ||
import { getCurrentInstance, onMounted } from 'vue' | ||
import * as monaco from 'monaco-editor' | ||
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker' | ||
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker' | ||
import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker' | ||
import HtmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker' | ||
import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker' | ||
|
||
import '/@monaco-types/vue' | ||
import '/@monaco-types/@vueuse/core' | ||
/* __imports__ */ | ||
|
||
import dark from 'theme-vitesse/themes/vitesse-dark.json' | ||
import light from 'theme-vitesse/themes/vitesse-light.json' | ||
export default async function setupMonaco() { | ||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ | ||
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(), | ||
noUnusedLocals: false, | ||
noUnusedParameters: false, | ||
allowUnreachableCode: true, | ||
allowUnusedLabels: true, | ||
strict: true, | ||
}) | ||
|
||
light.colors['editor.background'] = '#00000000' | ||
dark.colors['editor.background'] = '#00000000' | ||
await Promise.all([ | ||
// @ts-expect-error | ||
import('/@monaco-types/vue'), | ||
// @ts-expect-error | ||
import('/@monaco-types/@vueuse/core'), | ||
// load workers | ||
(async() => { | ||
const [ | ||
{ default: EditorWorker }, | ||
{ default: JsonWorker }, | ||
{ default: CssWorker }, | ||
{ default: HtmlWorker }, | ||
{ default: TsWorker }, | ||
] = await Promise.all([ | ||
import('monaco-editor/esm/vs/editor/editor.worker?worker'), | ||
import('monaco-editor/esm/vs/language/json/json.worker?worker'), | ||
import('monaco-editor/esm/vs/language/css/css.worker?worker'), | ||
import('monaco-editor/esm/vs/language/html/html.worker?worker'), | ||
import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'), | ||
]) | ||
|
||
monaco.editor.defineTheme('vitesse-light', light as any) | ||
monaco.editor.defineTheme('vitesse-dark', dark as any) | ||
// @ts-expect-error | ||
window.MonacoEnvironment = { | ||
getWorker(_: any, label: string) { | ||
if (label === 'json') | ||
return new JsonWorker() | ||
if (label === 'css' || label === 'scss' || label === 'less') | ||
return new CssWorker() | ||
if (label === 'html' || label === 'handlebars' || label === 'razor') | ||
return new HtmlWorker() | ||
if (label === 'typescript' || label === 'javascript') | ||
return new TsWorker() | ||
return new EditorWorker() | ||
}, | ||
} | ||
})(), | ||
]) | ||
|
||
// @ts-expect-error | ||
self.MonacoEnvironment = { | ||
getWorker(_: any, label: string) { | ||
if (label === 'json') | ||
return new JsonWorker() | ||
if (label === 'css' || label === 'scss' || label === 'less') | ||
return new CssWorker() | ||
if (label === 'html' || label === 'handlebars' || label === 'razor') | ||
return new HtmlWorker() | ||
if (label === 'typescript' || label === 'javascript') | ||
return new TsWorker() | ||
return new EditorWorker() | ||
}, | ||
} | ||
/* __async_injections__ */ | ||
|
||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ | ||
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(), | ||
noUnusedLocals: false, | ||
noUnusedParameters: false, | ||
allowUnreachableCode: true, | ||
allowUnusedLabels: true, | ||
strict: true, | ||
}) | ||
if (getCurrentInstance()) | ||
await new Promise<void>(resolve => onMounted(resolve)) | ||
|
||
export { monaco } | ||
return { monaco } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { existsSync } from 'fs' | ||
import { join, resolve } from 'path' | ||
import { slash } from '@antfu/utils' | ||
import { Plugin } from 'vite' | ||
import { ResolvedSlidevOptions } from './options' | ||
|
||
export function createSetupPlugin({ clientRoot, themeRoot, userRoot }: ResolvedSlidevOptions): Plugin { | ||
const setupEntry = slash(resolve(clientRoot, 'setup')) | ||
|
||
return { | ||
name: 'slidev:setup', | ||
enforce: 'pre', | ||
async transform(code, id) { | ||
if (id.startsWith(setupEntry)) { | ||
const name = id.slice(setupEntry.length + 1) | ||
const imports: string[] = [] | ||
const injections: string[] = [] | ||
const asyncInjections: string[] = [] | ||
|
||
const setups = [ | ||
join(themeRoot, 'setup', name), | ||
join(userRoot, 'setup', name), | ||
] | ||
|
||
setups.forEach((path, idx) => { | ||
if (!existsSync(path)) | ||
return | ||
|
||
imports.push(`import __n${idx} from '/@fs${slash(path)}'`) | ||
injections.push( | ||
`// ${path}`, | ||
`__n${idx}()`, | ||
) | ||
asyncInjections.push( | ||
`// ${path}`, | ||
`await __n${idx}()`, | ||
) | ||
}) | ||
|
||
code = code.replace('/* __imports__ */', imports.join('\n')) | ||
code = code.replace('/* __injections__ */', injections.join('\n')) | ||
code = code.replace('/* __async_injections__ */', asyncInjections.join('\n')) | ||
return code | ||
} | ||
|
||
return null | ||
}, | ||
} | ||
} |
Oops, something went wrong.