Support Vite 3.1 (#4752)
* Support Vite 3.1 * Update ~3.1.0 * Revert Vite bump
This commit is contained in:
parent
c5e134d035
commit
1bedb9427e
4 changed files with 13 additions and 11 deletions
5
.changeset/shaggy-books-give.md
Normal file
5
.changeset/shaggy-books-give.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support Vite 3.1
|
|
@ -340,17 +340,17 @@ ${source}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async handleHotUpdate(this: PluginContext, context) {
|
async handleHotUpdate(context) {
|
||||||
if (context.server.config.isProduction) return;
|
if (context.server.config.isProduction) return;
|
||||||
const compileProps: CompileProps = {
|
const compileProps: CompileProps = {
|
||||||
config,
|
config,
|
||||||
filename: context.file,
|
filename: context.file,
|
||||||
moduleId: context.file,
|
moduleId: context.file,
|
||||||
source: await context.read(),
|
source: await context.read(),
|
||||||
transformStyle: createTransformStyles(styleTransformer, context.file, true, this),
|
transformStyle: createTransformStyles(styleTransformer, context.file, true),
|
||||||
};
|
};
|
||||||
const compile = () => cachedCompilation(compileProps);
|
const compile = () => cachedCompilation(compileProps);
|
||||||
return handleHotUpdate.call(this, context, {
|
return handleHotUpdate(context, {
|
||||||
config,
|
config,
|
||||||
logging,
|
logging,
|
||||||
compile,
|
compile,
|
||||||
|
|
|
@ -30,14 +30,8 @@ export function createTransformStyles(
|
||||||
viteStyleTransformer: ViteStyleTransformer,
|
viteStyleTransformer: ViteStyleTransformer,
|
||||||
filename: string,
|
filename: string,
|
||||||
ssr: boolean,
|
ssr: boolean,
|
||||||
pluginContext: PluginContext
|
pluginContext?: PluginContext
|
||||||
): TransformStyle {
|
): TransformStyle {
|
||||||
// handleHotUpdate doesn't have `addWatchFile` used by transformStyleWithVite.
|
|
||||||
// TODO, refactor, why is this happening *here* ?
|
|
||||||
if (!pluginContext.addWatchFile) {
|
|
||||||
pluginContext.addWatchFile = () => {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedID = getNormalizedIDForPostCSS(filename);
|
const normalizedID = getNormalizedIDForPostCSS(filename);
|
||||||
|
|
||||||
return async function (styleSource, lang) {
|
return async function (styleSource, lang) {
|
||||||
|
|
|
@ -46,7 +46,10 @@ export function createTransformStyleWithViteFn(
|
||||||
|
|
||||||
viteDevServer?.moduleGraph.ensureEntryFromUrl(styleId, ssr, false);
|
viteDevServer?.moduleGraph.ensureEntryFromUrl(styleId, ssr, false);
|
||||||
|
|
||||||
const transformResult = await transformCss.call(this, source, styleId, ssr);
|
// This function could be called in a custom Vite hook like `handleHotUpdate`
|
||||||
|
// which doesn't have a context
|
||||||
|
const ctx = this ?? { addWatchFile: () => {} };
|
||||||
|
const transformResult = await transformCss.call(ctx, source, styleId, ssr);
|
||||||
|
|
||||||
// NOTE: only `code` and `map` are returned by vite:css
|
// NOTE: only `code` and `map` are returned by vite:css
|
||||||
const { code, map } = transformResult;
|
const { code, map } = transformResult;
|
||||||
|
|
Loading…
Add table
Reference in a new issue