MCPcopy
hub / github.com/zh-lx/code-inspector / WebpackCodeInjectLoader

Function WebpackCodeInjectLoader

packages/webpack/src/inject-loader.ts:7–37  ·  view source on GitHub ↗
(
  content: string,
  source: any,
  meta: any
)

Source from the content-addressed store, hash-verified

5} from '@code-inspector/core';
6
7export default function WebpackCodeInjectLoader(
8 content: string,
9 source: any,
10 meta: any
11): Promise<string> | undefined {
12 this.cacheable && this.cacheable(true);
13 const callback = this.async?.() || this.callback?.bind(this);
14 const filePath = normalizePath(this.resourcePath); // 当前文件的绝对路径
15 const options = this.query || {};
16
17 const result = (async () => {
18 if (isExcludedFile(filePath, options)) {
19 return content;
20 }
21
22 // start server and inject client code to entry file
23 return await getCodeWithWebComponent({
24 options,
25 file: filePath,
26 code: content,
27 record: options.record,
28 });
29 })().catch(() => content);
30
31 if (callback) {
32 result.then((code) => callback(null, code, source, meta));
33 return undefined;
34 }
35
36 return result;
37}

Callers

nothing calls this directly

Calls 3

normalizePathFunction · 0.90
isExcludedFileFunction · 0.90
getCodeWithWebComponentFunction · 0.90

Tested by

no test coverage detected