( content: string, source: any, meta: any )
| 5 | } from '@code-inspector/core'; |
| 6 | |
| 7 | export 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 | } |
nothing calls this directly
no test coverage detected