Skip to content

Commit

Permalink
feat(vite): support wasm asset file type (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoTwT committed Apr 8, 2024
1 parent f4e82b4 commit 5169dbf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/client/src/components/assets/AssetListItem.vue
Expand Up @@ -32,6 +32,8 @@ const icon = computed(() => {
return 'i-carbon-document'
if (props.item.type === 'json')
return 'i-carbon-json'
if (props.item.type === 'wasm')
return 'i-vscode-icons-file-type-wasm'
return 'i-carbon-document-blank'
})
</script>
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/components/assets/AssetPreview.vue
Expand Up @@ -29,6 +29,7 @@ defineProps<{
<div v-if="!detail" i-carbon-volume-up text-3xl op20 />
<audio v-else :src="asset.publicPath" controls />
</div>
<div v-else-if="asset.type === 'wasm'" i-vscode-icons-file-type-wasm text-3xl />
<div v-else i-carbon-help text-3xl op20 />
</div>
</template>
2 changes: 1 addition & 1 deletion packages/core/src/vite-bridge/module-types.ts
@@ -1,5 +1,5 @@
// assets
export type AssetType = 'image' | 'font' | 'video' | 'audio' | 'text' | 'json' | 'other'
export type AssetType = 'image' | 'font' | 'video' | 'audio' | 'text' | 'json' | 'wasm' | 'other'
export interface AssetInfo {
path: string
type: AssetType
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/modules/assets.ts
Expand Up @@ -50,6 +50,8 @@ function guessType(path: string): AssetType {
return 'font'
if (/\.(json[5c]?|te?xt|[mc]?[jt]sx?|md[cx]?|markdown|ya?ml|toml)/i.test(path))
return 'text'
if (/\.wasm/i.test(path))
return 'wasm'
return 'other'
}

Expand All @@ -73,6 +75,8 @@ export function setupAssetsModule(options: { rpc: ViteInspectAPI['rpc'], server:
'**/*.(woff2?|eot|ttf|otf|ttc|pfa|pfb|pfm|afm)',
// text
'**/*.(json|json5|jsonc|txt|text|tsx|jsx|md|mdx|mdc|markdown|yaml|yml|toml)',
// wasm
'**/*.wasm',
], {
cwd: dir,
onlyFiles: true,
Expand Down

0 comments on commit 5169dbf

Please sign in to comment.