Skip to content
Closed
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
21 changes: 21 additions & 0 deletions packages/bazel/src/builders/bazel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import {spawn} from 'child_process';
import {copyFileSync, existsSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync} from 'fs';
import {platform} from 'os';
import {dirname, join, normalize} from 'path';

export type Executable = 'bazel' | 'ibazel';
Expand Down Expand Up @@ -133,6 +134,24 @@ function replaceYarnWithNpm(source: string, dest: string) {
writeFileSync(dest, destContent);
}

/**
* Disable sandbox on Mac OS by setting spawn_strategy in .bazelrc.
* For a hello world (ng new) application, removing the sandbox improves build
* time by almost 40%.
* ng build with sandbox: 22.0 seconds
* ng build without sandbox: 13.3 seconds
*/
function disableSandbox(source: string, dest: string) {
const srcContent = readFileSync(source, 'utf-8');
const destContent = `${srcContent}
# Disable sandbox on Mac OS for performance reason.
build --spawn_strategy=local
run --spawn_strategy=local
test --spawn_strategy=local
`;
writeFileSync(dest, destContent);
}

/**
* Copy Bazel files (WORKSPACE, BUILD.bazel, etc) from the template directory to
* the project `root` directory, and return the absolute paths of the files
Expand All @@ -154,6 +173,8 @@ export function copyBazelFiles(root: string, templateDir: string) {
if (!existsSync(dest)) {
if (!useYarn && name === 'WORKSPACE') {
replaceYarnWithNpm(source, dest);
} else if (platform() === 'darwin' && name === '.bazelrc') {
disableSandbox(source, dest);
} else {
copyFileSync(source, dest);
}
Expand Down