mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-24 21:55:52 +02:00
29 lines
892 B
JavaScript
29 lines
892 B
JavaScript
import { transformAsync } from '@babel/core';
|
|
import linkerPlugin from '@angular/compiler-cli/linker/babel';
|
|
import { needsLinking } from '@angular/compiler-cli/linker';
|
|
|
|
export default function angularLinkerLoader(content, map) {
|
|
const callback = this.async();
|
|
(async () => {
|
|
try {
|
|
const filename = this.resourcePath;
|
|
if (!needsLinking(filename, content)) {
|
|
callback(null, content, map);
|
|
return;
|
|
}
|
|
// Create a fresh plugin instance per file. The linker plugin is stateful
|
|
// and cannot be shared across concurrent transforms.
|
|
const { code, map: resultMap } = await transformAsync(content, {
|
|
filename,
|
|
sourceFileName: filename,
|
|
sourceMaps: !!this.sourceMap,
|
|
compact: false,
|
|
plugins: [api => linkerPlugin(api, { sourceMapping: false })],
|
|
});
|
|
callback(null, code, resultMap || undefined);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
})();
|
|
}
|