Skip to content

Commit

Permalink
fix: support vite v3 (preactjs#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored and Interpause committed Aug 7, 2022
1 parent 91c3d84 commit 6211b60
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -42,7 +42,7 @@
},
"peerDependencies": {
"@babel/core": "7.x",
"vite": "2.x"
"vite": "2.x || 3.x"
},
"devDependencies": {
"@babel/core": "^7.15.8",
Expand Down
19 changes: 0 additions & 19 deletions src/index.ts
Expand Up @@ -3,7 +3,6 @@ import type { FilterPattern } from "@rollup/pluginutils";
import type { ParserPlugin, ParserOptions } from "@babel/parser";
import type { TransformOptions } from "@babel/core";

import resolve from "resolve";
import prefresh from "@prefresh/vite";
import { preactDevtoolsPlugin } from "./devtools.js";
import { createFilter, parseId } from "./utils.js";
Expand Down Expand Up @@ -89,24 +88,6 @@ export default function preactPlugin({
configResolved(resolvedConfig) {
config = resolvedConfig;
},
resolveId(id: string) {
return id === "preact/jsx-runtime" ? id : null;
},
load(id: string) {
if (id === "preact/jsx-runtime") {
const runtimePath = resolve.sync("preact/jsx-runtime", {
basedir: config.root,
});
const exports = ["jsx", "jsxs", "Fragment"];
return [
`import * as jsxRuntime from ${JSON.stringify(runtimePath)}`,
// We can't use `export * from` or else any callsite that uses
// this module will be compiled to `jsxRuntime.exports.jsx`
// instead of the more concise `jsx` alias.
...exports.map(name => `export const ${name} = jsxRuntime.${name}`),
].join("\n");
}
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
const { id } = parseId(url);
Expand Down

0 comments on commit 6211b60

Please sign in to comment.