chore: update to vite's hook filter (#3333)

Fixes https://github.com/denoland/fresh/issues/3331
This commit is contained in:
Marvin Hagemeister
2025-09-04 11:16:06 +02:00
committed by GitHub
parent baf774517b
commit b94aab2a1a
10 changed files with 432 additions and 418 deletions
+38 -35
View File
@@ -19,45 +19,48 @@ export function patches(): Plugin {
applyToEnvironment() {
return true;
},
transform(code, id, options) {
if (!JS_REG.test(id)) return;
transform: {
filter: {
id: JS_REG,
},
handler(code, id, options) {
const presets = [];
if (!options?.ssr && JSX_REG.test(id)) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
development: isDev,
}]);
}
const presets = [];
if (!options?.ssr && JSX_REG.test(id)) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
development: isDev,
}]);
}
const plugins: babel.PluginItem[] = [
cjsPlugin,
removePolyfills,
jsxComments,
inlineEnvVarsPlugin(
isDev ? "development" : "production",
),
];
const plugins: babel.PluginItem[] = [
cjsPlugin,
removePolyfills,
jsxComments,
inlineEnvVarsPlugin(
isDev ? "development" : "production",
),
];
if (!options?.ssr) {
plugins.push(denoGlobal);
}
if (!options?.ssr) {
plugins.push(denoGlobal);
}
const res = babel.transformSync(code, {
filename: id,
babelrc: false,
compact: true,
plugins,
presets,
});
const res = babel.transformSync(code, {
filename: id,
babelrc: false,
compact: true,
plugins,
presets,
});
if (res?.code) {
return {
code: res.code,
map: res.map,
};
}
if (res?.code) {
return {
code: res.code,
map: res.map,
};
}
},
},
};
}