Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 09e1139

Browse files
committed
refactor(webpack): write bundles to memory and disk
1 parent fb03df5 commit 09e1139

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/util/hybrid-file-system.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename, dirname } from 'path';
1+
import { basename, dirname, join } from 'path';
22
import { FileSystem, VirtualFileSystem } from './interfaces';
33
import { FileCache } from './file-cache';
44
import { VirtualDirStats, VirtualFileStats } from './virtual-file-utils';
@@ -104,4 +104,18 @@ export class HybridFileSystem implements FileSystem, VirtualFileSystem {
104104
getAllDirStats(): { [filePath: string]: VirtualDirStats } {
105105
return this.directoryStats;
106106
}
107+
108+
mkdirp(filePath: string, callback: Function) {
109+
callback();
110+
}
111+
112+
join(dirPath: string, fileName: string) {
113+
return join(dirPath, fileName);
114+
}
115+
116+
writeFile(filePath: string, fileContent: Buffer, callback: Function) {
117+
const stringContent = fileContent.toString();
118+
this.addVirtualFile(filePath, stringContent);
119+
callback();
120+
}
107121
}

src/webpack.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/c
88
import * as Constants from './util/constants';
99
import { BuildError, IgnorableError } from './util/errors';
1010
import { emit, EventType } from './util/events';
11-
import { getBooleanPropertyValue, printDependencyMap, webpackStatsToDependencyMap } from './util/helpers';
11+
import { getBooleanPropertyValue, printDependencyMap, webpackStatsToDependencyMap, writeFileAsync } from './util/helpers';
1212
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';
1313

1414

@@ -108,7 +108,13 @@ function webpackBuildComplete(stats: any, context: BuildContext, webpackConfig:
108108

109109
context.moduleFiles = files;
110110

111-
return Promise.resolve();
111+
return writeBundleFilesToDisk(context);
112+
}
113+
114+
export function writeBundleFilesToDisk(context: BuildContext) {
115+
const buildFiles = context.fileCache.getAll().filter(file => file.path.indexOf(context.buildDir) >= 0);
116+
const promises = buildFiles.map(buildFile => writeFileAsync(buildFile.path, buildFile.content));
117+
return Promise.all(promises);
112118
}
113119

114120
export function runWebpackFullBuild(config: WebpackConfig) {

src/webpack/ionic-environment-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class IonicEnvironmentPlugin {
3131
const hybridFileSystem = getInstance();
3232
hybridFileSystem.setFileSystem(compiler.inputFileSystem);
3333
compiler.inputFileSystem = hybridFileSystem;
34+
compiler.outputFileSystem = hybridFileSystem;
3435
compiler.watchFileSystem = new WatchMemorySystem(this.context.fileCache);
3536

3637
// do a bunch of webpack specific stuff here, so cast to an any

0 commit comments

Comments
 (0)