Skip to content

Commit

Permalink
feat(compile): file loader did not emit file
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Oct 7, 2023
1 parent 48dbbf3 commit bc2044e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/compiler/file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default async function FileLoader(content) {
interpolateName(this, name, content)
);
const metadata = generateMetadata(this.resourcePath, filePath);
this.emitFile(filePath, content);
return (
`export const metadata = ${JSON.stringify(metadata, null, 2)};\n` +
`export default ${JSON.stringify(filePath)};\n\n`
Expand Down
14 changes: 13 additions & 1 deletion lib/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,22 @@ export default async function compile(file, compilerOptions) {
);
}

/**
* @param {string} modulePath
* @param {LoaderContext} context
* @returns {ModuleCacheItem}
*/
function useModuleCache(modulePath, context) {
const outputPath = resolveModulePath(modulePath, context);
const outputDirPath = path.dirname(outputPath);
let cache = mdouleCacheMap[outputPath];
if (cache) {
return cache;
}
if (!fs.existsSync(outputDirPath)) {
if (
outputDirPath.startsWith(context.buildDirPath) &&
!fs.existsSync(outputDirPath)
) {
fs.mkdirpSync(outputDirPath);
}
cache = {
Expand Down Expand Up @@ -291,6 +299,10 @@ export default async function compile(file, compilerOptions) {
resourcePath,
resourceOutputPath: `${resourcePath}.h`,
context: path.dirname(resourcePath),
emitFile(name, content) {
logger.info(`Emitting ${name}`);
fs.writeFile(path.resolve(context.appDirPath, name), content);
},
emitError(error) {
printError(resourcePath, error);
},
Expand Down
3 changes: 3 additions & 0 deletions lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ interface CompilerContext extends CompilerOptions {
/** 引入与资源文件对应的模块 */
importModule(name: string): Promise<Module>;

/** 输出文件 */
emitFile(name: string, content: stirng | Buffer): void;

/** 生成模块 */
generateModule(
name: string,
Expand Down

0 comments on commit bc2044e

Please sign in to comment.