diff --git a/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template b/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template
index f3ce9dec8f..67d0dfaaa6 100644
--- a/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template
+++ b/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test_suite")
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "history_server")
+load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
ng_module(
@@ -33,22 +34,23 @@ rollup_bundle(
deps = ["//src"],
)
-# Needed because the prodserver only loads static files that appear under this
-# package.
-genrule(
- name = "zonejs",
- srcs = ["@npm//node_modules/zone.js:dist/zone.min.js"],
- outs = ["zone.min.js"],
- cmd = "cp $< $@",
+web_package(
+ name = "prodapp",
+ assets = [
+ # do not sort
+ "@npm//node_modules/zone.js:dist/zone.min.js",
+ ":bundle.min.js",
+ ],
+ data = [
+ ":bundle",
+ ],
+ index_html = "index.html",
)
history_server(
name = "prodserver",
- data = [
- "index.html",
- ":bundle",
- ":zonejs",
- ],
+ data = [":prodapp"],
+ templated_args = ["src/prodapp"],
)
ts_devserver(
@@ -63,8 +65,8 @@ ts_devserver(
static_files = [
"@npm//node_modules/zone.js:dist/zone.min.js",
"@npm//node_modules/tslib:tslib.js",
- "index.html",
],
+ index_html = "index.html",
deps = [":src"],
)
diff --git a/packages/bazel/src/schematics/bazel-workspace/index.ts b/packages/bazel/src/schematics/bazel-workspace/index.ts
index 014ea86c6a..d222d539ea 100644
--- a/packages/bazel/src/schematics/bazel-workspace/index.ts
+++ b/packages/bazel/src/schematics/bazel-workspace/index.ts
@@ -81,7 +81,7 @@ export default function(options: BazelWorkspaceOptions): Rule {
const workspaceVersions = {
'RULES_NODEJS_VERSION': '0.16.5',
- 'RULES_TYPESCRIPT_VERSION': '0.22.0',
+ 'RULES_TYPESCRIPT_VERSION': '0.22.1',
'ANGULAR_VERSION': existingVersions.Angular || clean(latestVersions.Angular),
'RXJS_VERSION': existingVersions.RxJs || clean(latestVersions.RxJs),
// TODO(kyliau): Consider moving this to latest-versions.ts
diff --git a/packages/bazel/src/schematics/ng-new/files/index.html.template b/packages/bazel/src/schematics/ng-new/files/index.html.template
deleted file mode 100644
index bfd3c9b8c9..0000000000
--- a/packages/bazel/src/schematics/ng-new/files/index.html.template
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
- <%= utils.classify(name) %>
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/bazel/src/schematics/ng-new/index.ts b/packages/bazel/src/schematics/ng-new/index.ts
index 22ada557cc..211ff2f8a6 100755
--- a/packages/bazel/src/schematics/ng-new/index.ts
+++ b/packages/bazel/src/schematics/ng-new/index.ts
@@ -15,6 +15,11 @@ import {validateProjectName} from '@schematics/angular/utility/validation';
import {getWorkspace} from '@schematics/angular/utility/config';
import {Schema} from './schema';
+/**
+ * Packages that build under Bazel require additional dev dependencies. This
+ * function adds those dependencies to "devDependencies" section in
+ * package.json.
+ */
function addDevDependenciesToPackageJson(options: Schema) {
return (host: Tree) => {
const packageJson = `${options.name}/package.json`;
@@ -38,8 +43,8 @@ function addDevDependenciesToPackageJson(options: Schema) {
// TODO(kyliau): Consider moving this to latest-versions.ts
'@bazel/bazel': '^0.21.0',
'@bazel/ibazel': '^0.9.0',
- '@bazel/karma': '^0.22.0',
- '@bazel/typescript': '^0.22.0',
+ '@bazel/karma': '^0.22.1',
+ '@bazel/typescript': '^0.22.1',
};
const recorder = host.beginUpdate(packageJson);
@@ -53,7 +58,13 @@ function addDevDependenciesToPackageJson(options: Schema) {
};
}
-function overwriteMainAndIndex(options: Schema) {
+/**
+ * Append main.dev.ts and main.prod.ts to src directory. These files are needed
+ * by Bazel for devserver and prodserver, respectively. They are different from
+ * main.ts generated by CLI because they use platformBrowser (AOT) instead of
+ * platformBrowserDynamic (JIT).
+ */
+function addDevAndProdMainForAot(options: Schema) {
return (host: Tree) => {
let newProjectRoot = '';
try {
@@ -63,18 +74,14 @@ function overwriteMainAndIndex(options: Schema) {
}
const srcDir = `${newProjectRoot}/${options.name}/src`;
- return mergeWith(
- apply(
- url('./files'),
- [
- applyTemplates({
- utils: strings,
- ...options,
- 'dot': '.',
- }),
- move(srcDir),
- ]),
- MergeStrategy.Overwrite);
+ return mergeWith(apply(url('./files'), [
+ applyTemplates({
+ utils: strings,
+ ...options,
+ 'dot': '.',
+ }),
+ move(srcDir),
+ ]));
};
}
@@ -199,8 +206,8 @@ export default function(options: Schema): Rule {
skipInstall: true,
}),
addDevDependenciesToPackageJson(options),
+ addDevAndProdMainForAot(options),
schematic('bazel-workspace', options),
- overwriteMainAndIndex(options),
overwriteGitignore(options),
updateWorkspaceFileToUseBazelBuilder(options),
]);
diff --git a/packages/bazel/src/schematics/ng-new/index_spec.ts b/packages/bazel/src/schematics/ng-new/index_spec.ts
index bec88e763c..946e162eaa 100644
--- a/packages/bazel/src/schematics/ng-new/index_spec.ts
+++ b/packages/bazel/src/schematics/ng-new/index_spec.ts
@@ -70,14 +70,22 @@ describe('Ng-new Schematic', () => {
expect(files).toContain('/demo/src/main.ts');
});
- it('should overwrite index.html with script tags', () => {
+ it('should not overwrite index.html with script tags', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('ng-new', options);
const {files} = host;
expect(files).toContain('/demo/src/index.html');
const content = host.readContent('/demo/src/index.html');
- expect(content).toMatch('');
- expect(content).toMatch('');
+ expect(content).not.toMatch('');
+ expect(content).not.toMatch('');
+ });
+
+ it('should generate main.dev.ts and main.prod.ts', () => {
+ const options = {...defaultOptions};
+ const host = schematicRunner.runSchematic('ng-new', options);
+ const {files} = host;
+ expect(files).toContain('/demo/src/main.dev.ts');
+ expect(files).toContain('/demo/src/main.prod.ts');
});
it('should overwrite .gitignore for bazel-out directory', () => {