diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 095ac6c622..79b533bf81 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -41,7 +41,7 @@ export class PrepareController extends EventEmitter { if (prepareData.watch) { result = await this.startWatchersWithPrepare(platformData, projectData, prepareData); } else { - await this.$webpackCompilerService.compileWithoutWatch(platformData, projectData, { watch: false, env: prepareData.env }); + await this.$webpackCompilerService.compileWithoutWatch(platformData, projectData, prepareData); await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData); } @@ -79,7 +79,7 @@ export class PrepareController extends EventEmitter { }; } - await this.startJSWatcherWithPrepare(platformData, projectData, { env: prepareData.env }); // -> start watcher + initial compilation + await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare const result = { platform: platformData.platformNameLowerCase, hasNativeChanges }; @@ -97,13 +97,13 @@ export class PrepareController extends EventEmitter { return result; } - private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise { + private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].webpackCompilerProcess) { this.$webpackCompilerService.on(WEBPACK_COMPILATION_COMPLETE, data => { this.emitPrepareEvent({ ...data, hasNativeChanges: false, platform: platformData.platformNameLowerCase }); }); - const childProcess = await this.$webpackCompilerService.compileWithWatch(platformData, projectData, config); + const childProcess = await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData); this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].webpackCompilerProcess = childProcess; } } diff --git a/lib/services/webpack/webpack-compiler-service.ts b/lib/services/webpack/webpack-compiler-service.ts index c549ebc0bc..6f42ba8f7d 100644 --- a/lib/services/webpack/webpack-compiler-service.ts +++ b/lib/services/webpack/webpack-compiler-service.ts @@ -14,7 +14,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp private $logger: ILogger ) { super(); } - public async compileWithWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise { + public async compileWithWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { return new Promise(async (resolve, reject) => { if (this.webpackProcesses[platformData.platformNameLowerCase]) { resolve(); @@ -22,8 +22,8 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp } let isFirstWebpackWatchCompilation = true; - config.watch = true; - const childProcess = await this.startWebpackProcess(platformData, projectData, config); + prepareData.watch = true; + const childProcess = await this.startWebpackProcess(platformData, projectData, prepareData); childProcess.on("message", (message: any) => { if (message === "Webpack compilation complete.") { @@ -68,14 +68,14 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp }); } - public async compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise { + public async compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { return new Promise(async (resolve, reject) => { if (this.webpackProcesses[platformData.platformNameLowerCase]) { resolve(); return; } - const childProcess = await this.startWebpackProcess(platformData, projectData, config); + const childProcess = await this.startWebpackProcess(platformData, projectData, prepareData); childProcess.on("close", (arg: any) => { const exitCode = typeof arg === "number" ? arg : arg && arg.code; if (exitCode === 0) { @@ -99,8 +99,8 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp @performanceLog() @hook('prepareJSApp') - private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise { - const envData = this.buildEnvData(platformData.platformNameLowerCase, config.env, projectData); + private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { + const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData); const envParams = this.buildEnvCommandLineParams(envData, platformData); const args = [ @@ -110,11 +110,11 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp ...envParams ]; - if (config.watch) { + if (prepareData.watch) { args.push("--watch"); } - const stdio = config.watch ? ["inherit", "inherit", "inherit", "ipc"] : "inherit"; + const stdio = prepareData.watch ? ["inherit", "inherit", "inherit", "ipc"] : "inherit"; const childProcess = this.$childProcess.spawn("node", args, { cwd: projectData.projectDir, stdio }); this.webpackProcesses[platformData.platformNameLowerCase] = childProcess; @@ -122,7 +122,8 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp return childProcess; } - private buildEnvData(platform: string, env: any, projectData: IProjectData) { + private buildEnvData(platform: string, projectData: IProjectData, prepareData: IPrepareData) { + const { env } = prepareData; const envData = Object.assign({}, env, { [platform.toLowerCase()]: true } @@ -137,6 +138,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp ); envData.verbose = this.$logger.isVerbose(); + envData.production = prepareData.release; return envData; } diff --git a/lib/services/webpack/webpack.d.ts b/lib/services/webpack/webpack.d.ts index 0777d63f74..b0e5e56388 100644 --- a/lib/services/webpack/webpack.d.ts +++ b/lib/services/webpack/webpack.d.ts @@ -4,19 +4,15 @@ import { PrepareData } from "../../data/prepare-data"; declare global { interface IWebpackCompilerService extends EventEmitter { - compileWithWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise; - compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise; + compileWithWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise; + compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise; stopWebpackCompiler(platform: string): void; } - interface IWebpackCompilerConfig { - env: IWebpackEnvOptions; - watch?: boolean; - } - interface IWebpackEnvOptions { sourceMap?: boolean; uglify?: boolean; + production?: boolean; } interface IProjectChangesService {