Skip to content

Commit

Permalink
fix(stats): add bundle output paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 10, 2018
1 parent ebac416 commit 38c2ea1
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/compiler/bundle/generate-bundles.ts
Expand Up @@ -41,7 +41,7 @@ export async function generateBundles(config: Config, compilerCtx: CompilerCtx,
.map(async ([key, value]) => {
const fileName = getBundleFilename(key.replace('.js', ''), false, 'es2015');
const jsText = replaceBundleIdPlaceholder(value.code, key);
await writeJSFile(config, compilerCtx, fileName, jsText);
await writeBundleJSFile(config, compilerCtx, fileName, jsText);
});
await Promise.all(esmPromises);

Expand All @@ -54,7 +54,7 @@ export async function generateBundles(config: Config, compilerCtx: CompilerCtx,
const fileName = getBundleFilename(key.replace('.js', ''), false, 'es5');
let jsText = replaceBundleIdPlaceholder(value.code, key);
jsText = await transpileEs5Bundle(compilerCtx, buildCtx, jsText);
await writeJSFile(config, compilerCtx, fileName, jsText);
await writeBundleJSFile(config, compilerCtx, fileName, jsText);
});
await Promise.all(es5Promises);
}
Expand All @@ -67,6 +67,25 @@ export async function generateBundles(config: Config, compilerCtx: CompilerCtx,
return cmpRegistry;
}

async function writeBundleJSFile(config: Config, compilerCtx: CompilerCtx, fileName: string, jsText: string) {

// get the absolute path to where it'll be saved in www
const wwwBuildPath = pathJoin(config, getAppWWWBuildDir(config), fileName);

// get the absolute path to where it'll be saved in dist
const distPath = pathJoin(config, getAppDistDir(config), fileName);

if (config.generateWWW) {
// write to the www build
await compilerCtx.fs.writeFile(wwwBuildPath, jsText);
}

if (config.generateDistribution) {
// write to the dist build
await compilerCtx.fs.writeFile(distPath, jsText);
}
}

async function generateBundleMode(config: Config, compilerCtx: CompilerCtx, buildCtx: BuildCtx, entryModule: EntryModule, modeName: string, jsCode: { [key: string]: string }) {

// create js text for: mode, no scoped styles and esm
Expand Down Expand Up @@ -158,12 +177,6 @@ async function generateBundleBuild(config: Config, compilerCtx: CompilerCtx, ent
entryModule.entryBundles = entryModule.entryBundles || [];
entryModule.entryBundles.push(entryBundle);

await writeJSFile(config, compilerCtx, fileName, jsText);
}


async function writeJSFile(config: Config, compilerCtx: CompilerCtx, fileName: string, jsText: string) {

// get the absolute path to where it'll be saved in www
const wwwBuildPath = pathJoin(config, getAppWWWBuildDir(config), fileName);

Expand All @@ -173,14 +186,17 @@ async function writeJSFile(config: Config, compilerCtx: CompilerCtx, fileName: s
if (config.generateWWW) {
// write to the www build
await compilerCtx.fs.writeFile(wwwBuildPath, jsText);
entryBundle.outputs.push(wwwBuildPath);
}

if (config.generateDistribution) {
// write to the dist build
await compilerCtx.fs.writeFile(distPath, jsText);
entryBundle.outputs.push(distPath);
}
}


function injectStyleMode(moduleFiles: ModuleFile[], jsText: string, modeName: string, isScopedStyles: boolean) {
moduleFiles.forEach(moduleFile => {
jsText = injectComponentStyleMode(moduleFile.cmpMeta, modeName, jsText, isScopedStyles);
Expand Down

0 comments on commit 38c2ea1

Please sign in to comment.