-
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.
fix(bundler-vite): serve assets with absolute path in dev server corr…
…ectly (close #1442)
- Loading branch information
Showing
11 changed files
with
104 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
![logo-public](/logo.png) | ||
|
||
![logo-relative](./logo-relative.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
describe('markdown > images', () => { | ||
it('should render images correctly', () => { | ||
cy.visit('/markdown/images/images.html') | ||
|
||
cy.get('.e2e-theme-content img') | ||
.should('have.length', 2) | ||
.each<HTMLImageElement>(([el]) => { | ||
cy.request({ url: el.src, failOnStatusCode: false }).then((res) => { | ||
expect(res.status).to.equal(200) | ||
expect(el.naturalWidth).to.be.greaterThan(0) | ||
}) | ||
}) | ||
|
||
cy.get('.e2e-theme-content img') | ||
.first() | ||
.should('have.attr', 'alt', 'logo-public') | ||
|
||
cy.get('.e2e-theme-content img') | ||
.last() | ||
.should('have.attr', 'alt', 'logo-relative') | ||
}) | ||
}) |
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,2 +1,3 @@ | ||
export * from './mainPlugin.js' | ||
export * from './userConfigPlugin.js' | ||
export * from './vuepressMainPlugin.js' | ||
export * from './vuepressUserConfigPlugin.js' | ||
export * from './vuepressVuePlugin.js' |
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,58 @@ | ||
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' | ||
|
||
/** | ||
* Wrapper of official vue plugin | ||
*/ | ||
export const vuepressVuePlugin = (options: ViteBundlerOptions): Plugin => { | ||
return vuePlugin({ | ||
...options.vuePluginOptions, | ||
template: { | ||
...options.vuePluginOptions?.template, | ||
transformAssetUrls: resolveTransformAssetUrls(options), | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* 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, | ||
} | ||
} |
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