| 100 | export default kumaUiLoader; |
| 101 | |
| 102 | export 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 | } |