-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bundler-vite): remove vite-root temp dir and clean up stale …
…fix for vue plugin
- Loading branch information
Showing
3 changed files
with
30 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,11 @@ | ||
import vuePlugin from '@vitejs/plugin-vue' | ||
import type { Plugin } from 'vite' | ||
import type { AssetURLOptions, AssetURLTagConfig } from 'vue/compiler-sfc' | ||
import type { ViteBundlerOptions } from '../types.js' | ||
|
||
/** | ||
* Determine if the given `transformAssetUrls` option is `AssetURLTagConfig` | ||
*/ | ||
const isAssetURLTagConfig = ( | ||
transformAssetUrls: AssetURLOptions | AssetURLTagConfig, | ||
): transformAssetUrls is AssetURLTagConfig => | ||
Object.values(transformAssetUrls).some((val) => Array.isArray(val)) | ||
|
||
/** | ||
* Resolve `template.transformAssetUrls` option from user config | ||
*/ | ||
const resolveTransformAssetUrls = ( | ||
options: ViteBundlerOptions, | ||
): AssetURLOptions => { | ||
// default transformAssetUrls option | ||
const defaultTransformAssetUrls = { includeAbsolute: true } | ||
|
||
// user provided transformAssetUrls option | ||
const { transformAssetUrls: userTransformAssetUrls } = | ||
options.vuePluginOptions?.template ?? {} | ||
|
||
// if user does not provide an object as transformAssetUrls | ||
if (typeof userTransformAssetUrls !== 'object') { | ||
return defaultTransformAssetUrls | ||
} | ||
|
||
// AssetURLTagConfig | ||
if (isAssetURLTagConfig(userTransformAssetUrls)) { | ||
return { | ||
...defaultTransformAssetUrls, | ||
tags: userTransformAssetUrls, | ||
} | ||
} | ||
|
||
// AssetURLOptions | ||
return { | ||
...defaultTransformAssetUrls, | ||
...userTransformAssetUrls, | ||
} | ||
} | ||
|
||
/** | ||
* Wrapper of official vue plugin | ||
* Wrapper of the official vue plugin | ||
*/ | ||
export const vuepressVuePlugin = (options: ViteBundlerOptions): Plugin => | ||
vuePlugin({ | ||
...options.vuePluginOptions, | ||
template: { | ||
...options.vuePluginOptions?.template, | ||
transformAssetUrls: resolveTransformAssetUrls(options), | ||
}, | ||
}) |
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