Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,73 @@ const store = useStore(
<Sandbox :store="store" />
</template>
```

<details>
<summary>Configuration options for resource links. (replace CDN resources)</summary>

```ts
export type ResourceLinkConfigs = {
/** URL for ES Module Shims. */
esModuleShims?: string
/** Function that generates the Vue compiler URL based on the version. */
vueCompilerUrl?: (version: string) => string
/** Function that generates the TypeScript library URL based on the version. */
typescriptLib?: (version: string) => string

/** [monaco] Function that generates a URL to fetch the latest version of a package. */
pkgLatestVersionUrl?: (pkgName: string) => string
/** [monaco] Function that generates a URL to browse a package directory. */
pkgDirUrl?: (pkgName: string, pkgVersion: string, pkgPath: string) => string
/** [monaco] Function that generates a URL to fetch the content of a file from a package. */
pkgFileTextUrl?: (
pkgName: string,
pkgVersion: string | undefined,
pkgPath: string,
) => string
}
```

**unpkg**

```ts
const store = useStore({
resourceLinks: ref({
esModuleShims:
'https://unpkg.com/[email protected]/dist/es-module-shims.wasm.js',
vueCompilerUrl: (version) =>
`https://unpkg.com/@vue/compiler-sfc@${version}/dist/compiler-sfc.esm-browser.js`,
typescriptLib: (version) =>
`https://unpkg.com/typescript@${version}/lib/typescript.js`,
pkgLatestVersionUrl: (pkgName) =>
`https://unpkg.com/${pkgName}@latest/package.json`,
pkgDirUrl: (pkgName, pkgVersion, pkgPath) =>
`https://unpkg.com/${pkgName}@${pkgVersion}/${pkgPath}/?meta`,
pkgFileTextUrl: (pkgName, pkgVersion, pkgPath) =>
`https://unpkg.com/${pkgName}@${pkgVersion || 'latest'}/${pkgPath}`,
}),
})
```

**npmmirror**

```ts
const store = useStore({
resourceLinks: ref({
esModuleShims:
'https://registry.npmmirror.com/es-module-shims/1.5.18/files/dist/es-module-shims.wasm.js',
vueCompilerUrl: (version) =>
`https://registry.npmmirror.com/@vue/compiler-sfc/${version}/files/dist/compiler-sfc.esm-browser.js`,
typescriptLib: (version) =>
`https://registry.npmmirror.com/typescript/${version}/files/lib/typescript.js`,

pkgLatestVersionUrl: (pkgName) =>
`https://registry.npmmirror.com/${pkgName}/latest/files/package.json`,
pkgDirUrl: (pkgName, pkgVersion, pkgPath) =>
`https://registry.npmmirror.com/${pkgName}/${pkgVersion}/files/${pkgPath}/?meta`,
pkgFileTextUrl: (pkgName, pkgVersion, pkgPath) =>
`https://registry.npmmirror.com/${pkgName}/${pkgVersion || 'latest'}/files/${pkgPath}`,
}),
})
```

</details>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@types/node": "^24.2.0",
"@vitejs/plugin-vue": "^6.0.1",
"@volar/jsdelivr": "2.4.23",
"@volar/language-service": "~2.4.11",
"@volar/monaco": "2.4.23",
"@volar/typescript": "2.4.23",
"@vue/babel-plugin-jsx": "^1.4.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions src/monaco/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export interface WorkerMessage {
event: 'init'
tsVersion: string
tsLocale?: string
pkgDirUrl?: string
pkgFileTextUrl?: string
pkgLatestVersionUrl?: string
typescriptLib?: string
}

export function loadMonacoEnv(store: Store) {
Expand All @@ -135,11 +139,27 @@ export function loadMonacoEnv(store: Store) {
resolve()
}
})
worker.postMessage({

const {
pkgDirUrl,
pkgFileTextUrl,
pkgLatestVersionUrl,
typescriptLib,
} = store.resourceLinks || {}

const message: WorkerMessage = {
event: 'init',
tsVersion: store.typescriptVersion,
tsLocale: store.locale,
} satisfies WorkerMessage)
pkgDirUrl: pkgDirUrl ? String(pkgDirUrl) : undefined,
pkgFileTextUrl: pkgFileTextUrl ? String(pkgFileTextUrl) : undefined,
pkgLatestVersionUrl: pkgLatestVersionUrl
? String(pkgLatestVersionUrl)
: undefined,
typescriptLib: typescriptLib ? String(typescriptLib) : undefined,
}

worker.postMessage(message)
})
await init
return worker
Expand Down
Loading
Loading