Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support vite v3 #50

Merged
merged 1 commit into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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