Skip to content

feat: set webpack in production mode based on --release option #4660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 };
Expand All @@ -97,13 +97,13 @@ export class PrepareController extends EventEmitter {
return result;
}

private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<void> {
private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {
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;
}
}
Expand Down
22 changes: 12 additions & 10 deletions lib/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
private $logger: ILogger
) { super(); }

public async compileWithWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<any> {
public async compileWithWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<any> {
return new Promise(async (resolve, reject) => {
if (this.webpackProcesses[platformData.platformNameLowerCase]) {
resolve();
return;
}

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.") {
Expand Down Expand Up @@ -68,14 +68,14 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
});
}

public async compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<void> {
public async compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {
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) {
Expand All @@ -99,8 +99,8 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp

@performanceLog()
@hook('prepareJSApp')
private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<child_process.ChildProcess> {
const envData = this.buildEnvData(platformData.platformNameLowerCase, config.env, projectData);
private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<child_process.ChildProcess> {
const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
const envParams = this.buildEnvCommandLineParams(envData, platformData);

const args = [
Expand All @@ -110,19 +110,20 @@ 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;

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 }
Expand All @@ -137,6 +138,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
);

envData.verbose = this.$logger.isVerbose();
envData.production = prepareData.release;

return envData;
}
Expand Down
10 changes: 3 additions & 7 deletions lib/services/webpack/webpack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import { PrepareData } from "../../data/prepare-data";

declare global {
interface IWebpackCompilerService extends EventEmitter {
compileWithWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<any>;
compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, config: IWebpackCompilerConfig): Promise<void>;
compileWithWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<any>;
compileWithoutWatch(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void>;
stopWebpackCompiler(platform: string): void;
}

interface IWebpackCompilerConfig {
env: IWebpackEnvOptions;
watch?: boolean;
}

interface IWebpackEnvOptions {
sourceMap?: boolean;
uglify?: boolean;
production?: boolean;
}

interface IProjectChangesService {
Expand Down