MCPcopy
hub / github.com/kuma-ui/kuma-ui / fileLoader

Function fileLoader

packages/webpack-plugin/src/loader.ts:102–120  ·  view source on GitHub ↗
(
  src: string,
  options: {
    context: LoaderContext<unknown>;
    outputDir: string;
  },
)

Source from the content-addressed store, hash-verified

100export default kumaUiLoader;
101
102export function fileLoader(
103 src: string,
104 options: {
105 context: LoaderContext<unknown>;
106 outputDir: string;
107 },
108) {
109 const outDir = options.outputDir;
110 if (!fs.existsSync(outDir)) fs.mkdirSync(outDir);
111 const hash = createHash("md5").update(src).digest("hex");
112 const srcPath = path.posix.join(outDir, `${hash}.css`);
113 fs.writeFileSync(srcPath, src);
114
115 // Compute the relative path from the current file location to the output directory
116 const currentDir = options.context.context;
117 const relativeSrcPath = path.relative(currentDir, srcPath);
118
119 return `import "${relativeSrcPath}";`;
120}

Callers 1

kumaUiLoaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected