Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat: 使用新的this.emitFile api 生成文件
Browse files Browse the repository at this point in the history
  • Loading branch information
newset authored and yesmeck committed Sep 16, 2019
1 parent 1e01c5c commit 941f522
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/remax-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"mkdirp": "^0.5.1",
"named-exports-db": "^0.0.1",
"postcss-url": "^8.0.0",
"rollup": "^1.16.0",
"regenerator-runtime": "^0.13.0",
"rollup": "^1.21.3",
"rollup-plugin-alias": "^1.5.2",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-clear": "^2.0.7",
Expand Down
36 changes: 16 additions & 20 deletions packages/remax-cli/src/build/plugins/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ async function createTemplate(pageFile: string, adapter: Adapter) {

return {
fileName,
type: 'asset' as 'asset',
isAsset: true as true,
source: code,
};
}
Expand All @@ -46,8 +44,6 @@ async function createHelperFile(adapter: Adapter) {

return {
fileName: `helper${adapter.extensions.jsHelper}`,
type: 'asset' as 'asset',
isAsset: true as true,
source: code,
};
}
Expand All @@ -73,8 +69,6 @@ async function createBaseTemplate(adapter: Adapter, options: RemaxOptions) {

return {
fileName: `base${adapter.extensions.template}`,
type: 'asset' as 'asset',
isAsset: true as true,
source: code,
};
}
Expand All @@ -89,8 +83,6 @@ function createAppManifest(
: readManifest(path.resolve(options.cwd, 'src/app.config.js'), target);
return {
fileName: 'app.json',
type: 'asset' as 'asset',
isAsset: true as true,
source: JSON.stringify(config, null, 2),
};
}
Expand All @@ -111,8 +103,6 @@ function createPageManifest(
if (fs.existsSync(configFilePath)) {
return {
fileName: manifestFile,
isAsset: true as true,
type: 'asset' as 'asset',
source: JSON.stringify(readManifest(configFilePath, target), null, 2),
};
}
Expand All @@ -123,8 +113,6 @@ function createPageManifest(
const { path, ...config } = pageConfig;
return {
fileName: manifestFile,
isAsset: true as true,
type: 'asset' as 'asset',
source: JSON.stringify(config, null, 2),
};
}
Expand Down Expand Up @@ -165,16 +153,17 @@ export default function template(
): Plugin {
return {
name: 'template',
generateBundle: async (_, bundle) => {
async generateBundle(_, bundle) {
const templateAssets = [];
// app.json
const manifest = createAppManifest(options, adapter.name, context);
bundle[manifest.fileName] = manifest;

const template = await createBaseTemplate(adapter, options);
bundle[template.fileName] = template;
templateAssets.push(template, manifest);

const helperFile = await createHelperFile(adapter);
bundle[helperFile.fileName] = helperFile;
if (adapter.templates.jsHelper) {
const helperFile = await createHelperFile(adapter);
templateAssets.push(helperFile);
}

const entries = getEntries(options, adapter, context);
const { pages } = entries;
Expand All @@ -188,7 +177,7 @@ export default function template(
const page = pages.find(p => p.file === filePath);
if (page) {
const template = await createTemplate(file, adapter);
bundle[template.fileName] = template;
templateAssets.push(template);
const config = await createPageManifest(
options,
file,
Expand All @@ -198,12 +187,19 @@ export default function template(
);

if (config) {
bundle[config.fileName] = config;
templateAssets.push(config);
}
}
}
}),
]);

templateAssets.forEach(file => {
this.emitFile({
type: 'asset',
...file,
});
});
},
};
}

0 comments on commit 941f522

Please sign in to comment.