@@ -5,6 +5,7 @@ load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
55load ("@npm//@babel/cli:index.bzl" , "babel" )
66load ("@npm//history-server:index.bzl" , "history_server" )
77load ("@npm_angular_bazel//:index.bzl" , "ng_module" )
8+ load ("@npm_bazel_inject_html//:index.bzl" , "inject_html" )
89load ("@npm_bazel_rollup//:index.bzl" , "rollup_bundle" )
910load ("@npm_bazel_terser//:index.bzl" , "terser_minified" )
1011load ("@npm_bazel_typescript//:index.bzl" , "ts_config" , "ts_devserver" , "ts_library" )
@@ -85,23 +86,22 @@ _ASSETS = [
8586 "@npm//:node_modules/zone.js/dist/zone.min.js" ,
8687]
8788
89+ inject_html (
90+ name = "inject_scripts_for_dev" ,
91+ src = "//src:example/index.html" ,
92+ assets = _ASSETS + ["_/ts_scripts.js" ],
93+ )
94+
8895# This devserver is written in Go and is super-fast.
8996# It doesn't run any bundler or code splitter. Instead, it concatenates
9097# named UMD and named AMD JavaScript code on-the-fly in-memory.
9198# This scales really well for massive codebases.
9299ts_devserver (
93100 name = "devserver" ,
94- # Serve these files but don't inject tags for them into the index file
95- # This might be because we only want to lazy-load these scripts on-demand,
96- # or because they aren't compatible with Require.js so we must use a runtime
97- # loader to load them.
98- data = [
99- "//src/assets" ,
100- ],
101- # Start from the development version of the main
101+ # Serve src/example/index.html at /index.html
102+ additional_root_paths = ["src/example" ],
103+ # Run the program from the development version of the main
102104 entry_module = "examples_angular/src/main.dev" ,
103- # <script> and <link> tags will be automatically injected into this index file
104- index_html = "//src/example:index.dev.html" ,
105105 # These scripts will be included in the JS bundle after require.js
106106 # They should have only named UMD modules, or require.js will throw.
107107 scripts = [
@@ -114,8 +114,10 @@ ts_devserver(
114114 "@npm//date-fns:date-fns.umd.js" ,
115115 ],
116116 # Serve these files in addition to the JavaScript bundle
117- # The corresponding <script> or <link> tags will be injected into the index_html
118- static_files = _ASSETS ,
117+ static_files = _ASSETS + [
118+ ":inject_scripts_for_dev" ,
119+ "//src/assets" ,
120+ ],
119121 # Tell Bazel to build the sources first
120122 deps = ["//src" ],
121123)
@@ -161,28 +163,40 @@ terser_minified(
161163 src = ":bundle-es5" ,
162164)
163165
166+ inject_html (
167+ name = "inject_scripts_for_prod" ,
168+ src = "//src:example/index.prod.html" ,
169+ # we can't produce "example/index.html" since that collides with the devmode file
170+ # web_package rule will re-root this path because it starts with _prodapp
171+ out = "_prodapp/src/example/index.html" ,
172+ assets = _ASSETS ,
173+ )
174+
164175web_package (
165176 name = "prodapp" ,
166177 # In production mode we serve some polyfills with script tags that have hard-coded paths in the index.html
167178 # so we must serve them at that path, by stripping a prefix
168179 additional_root_paths = [
169180 "npm/node_modules/core-js/client" ,
170181 "npm/node_modules/systemjs/dist" ,
182+ "src/_prodapp" ,
171183 ],
172- # do not sort
173184 assets = _ASSETS + [
174185 ":bundle-es2015.min" ,
175186 ":bundle-es5.min" ,
176- ],
177- data = [
187+ ":inject_scripts_for_prod" ,
178188 "//src/assets" ,
179189 # Include polyfills that will be requested by old browsers
180190 "@npm//:node_modules/systemjs/dist/system.js" ,
181191 "@npm//:node_modules/core-js/client/core.min.js" ,
182192 "index.html" ,
183193 ],
184- # <script> and <link> tags will be automatically injected into this index.
185- index_html = "//src/example:index.html" ,
194+ # In production mode we serve some polyfills with script tags that have hard-coded paths in the index.html
195+ # so we must serve them at that path, by stripping a prefix
196+ additional_root_paths = [
197+ "npm/node_modules/core-js/client" ,
198+ "npm/node_modules/systemjs/dist" ,
199+ ],
186200)
187201
188202history_server (
0 commit comments