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

resolveHook didn't call #88

Closed
ysy945 opened this issue Mar 17, 2023 · 0 comments · Fixed by #90
Closed

resolveHook didn't call #88

ysy945 opened this issue Mar 17, 2023 · 0 comments · Fixed by #90

Comments

@ysy945
Copy link
Contributor

ysy945 commented Mar 17, 2023

  • this is the code of loadHook.

image

  • the next step should be to parse the "App. vue? Lang=css..." file, but the "resolveHook" does not work. The following is the relevant code.
export default function farmVuePlugin(options: object = {}): JsPlugin {
  return {
    name: "farm-vue-plugin",
    resolve: {
      filters: {
        importers: [".vue$"],
        sources: [".*"],
      },
      executor(params, ctx) {
        console.log("resolve:", params.source);
        const { query, filePath } = parsePath(params.source as string);
        query.resolvedPath = params.source as string;
        console.log("beforeQuery:", query);
        return {
          external: false,
          resolvedPath: filePath,
          sideEffects: false,
          query,
          meta: {},
        };
      },
    },
    load: {
      filters: {
        resolvedPaths: [".vue$"],
      },
      executor(params, ctx) {
        const { resolvedPath, query } = params;
        if (query.vue === "true" && query.hash) {
          const styleCode = stylesCodeCache[query.hash];
          return {
            content: typeof styleCode === "string" ? styleCode : "",
            moduleType: query.lang,
          };
        }
        let source = "";
        try {
          source = fs.readFileSync(resolvedPath, "utf-8");
        } catch (err) {
          error({
            id: resolvedPath,
            message: "path is not right,can't readFile",
          });
        }

        const { descriptor } = compiler.parse(source);
        const { source: mainCode, moduleType } = genMainCode(
          descriptor,
          resolvedPath
        );
        return {
          content: mainCode,
          moduleType,
        };
      },
    },
  };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant