@@ -5,7 +5,7 @@ esbuild rule
55load ("@build_bazel_rules_nodejs//:index.bzl" , "nodejs_binary" )
66load ("@build_bazel_rules_nodejs//:providers.bzl" , "JSEcmaScriptModuleInfo" , "JSModuleInfo" , "NpmPackageInfo" , "node_modules_aspect" , "run_node" )
77load ("@build_bazel_rules_nodejs//internal/linker:link_node_modules.bzl" , "MODULE_MAPPINGS_ASPECT_RESULTS_NAME" , "module_mappings_aspect" )
8- load (":helpers.bzl" , "filter_files" , "generate_path_mapping" , "resolve_entry_point" , "write_jsconfig_file" )
8+ load (":helpers.bzl" , "desugar_entry_point_names" , " filter_files" , "generate_path_mapping" , "resolve_entry_point" , "write_jsconfig_file" )
99
1010def _esbuild_impl (ctx ):
1111 # For each dep, JSEcmaScriptModuleInfo is used if found, then JSModuleInfo and finally
@@ -38,18 +38,21 @@ def _esbuild_impl(ctx):
3838 package_name = key .split (":" )[0 ]
3939 path_alias_mappings .update (generate_path_mapping (package_name , value [1 ].replace (ctx .bin_dir .path + "/" , "" )))
4040
41+ entry_points = desugar_entry_point_names (ctx .file .entry_point , ctx .files .entry_points )
42+
4143 deps_inputs = depset (transitive = deps_depsets ).to_list ()
42- inputs = filter_files (ctx . files . entry_point ) + ctx .files .srcs + deps_inputs
44+ inputs = filter_files (entry_points ) + ctx .files .srcs + deps_inputs
4345
4446 metafile = ctx .actions .declare_file ("%s_metadata.json" % ctx .attr .name )
4547 outputs = [metafile ]
4648
47- entry_point = resolve_entry_point (ctx .file .entry_point , inputs , ctx .files .srcs )
48-
4949 args = ctx .actions .args ()
5050 args .use_param_file (param_file_arg = "--esbuild_flags=%s" , use_always = True )
5151
52- args .add ("--bundle" , entry_point .path )
52+ # the entry point files to bundle
53+ for entry_point in entry_points :
54+ args .add (resolve_entry_point (entry_point , inputs , ctx .files .srcs ))
55+ args .add ("--bundle" )
5356
5457 if len (ctx .attr .sourcemap ) > 0 :
5558 args .add_joined (["--sourcemap" , ctx .attr .sourcemap ], join_with = "=" )
@@ -126,7 +129,7 @@ def _esbuild_impl(ctx):
126129 inputs = depset (inputs ),
127130 outputs = outputs ,
128131 arguments = [launcher_args , args ],
129- progress_message = "%s Javascript %s [esbuild]" % ("Bundling" if not ctx .attr .output_dir else "Splitting" , entry_point .short_path ),
132+ progress_message = "%s Javascript %s [esbuild]" % ("Bundling" if not ctx .attr .output_dir else "Splitting" , " " . join ([ entry_point .short_path for entry_point in entry_points ]) ),
130133 execution_requirements = execution_requirements ,
131134 mnemonic = "esbuild" ,
132135 env = env ,
@@ -168,9 +171,19 @@ See https://esbuild.github.io/api/#define for more details
168171 doc = "A list of direct dependencies that are required to build the bundle" ,
169172 ),
170173 "entry_point" : attr .label (
171- mandatory = True ,
172174 allow_single_file = True ,
173- doc = "The bundle's entry point (e.g. your main.js or app.js or index.js)" ,
175+ doc = """The bundle's entry point (e.g. your main.js or app.js or index.js)
176+
177+ This is a shortcut for the `entry_points` attribute with a single entry.
178+ Specify either this attribute or `entry_point`, but not both.
179+ """ ,
180+ ),
181+ "entry_points" : attr .label_list (
182+ allow_files = True ,
183+ doc = """The bundle's entry points (e.g. your main.js or app.js or index.js)
184+
185+ Specify either this attribute or `entry_point`, but not both.
186+ """ ,
174187 ),
175188 "external" : attr .string_list (
176189 default = [],
@@ -183,7 +196,7 @@ See https://esbuild.github.io/api/#external for more details
183196 values = ["iife" , "cjs" , "esm" , "" ],
184197 mandatory = False ,
185198 doc = """The output format of the bundle, defaults to iife when platform is browser
186- and cjs when platform is node. If performing code splitting, defaults to esm.
199+ and cjs when platform is node. If performing code splitting or multiple entry_points are specified , defaults to esm.
187200
188201See https://esbuild.github.io/api/#format for more details
189202 """ ,
@@ -229,9 +242,9 @@ file is named 'foo.js', you should set this to 'foo.css'.""",
229242 ),
230243 "output_dir" : attr .bool (
231244 default = False ,
232- doc = """If true, esbuild produces an output directory containing all the output files from code splitting
245+ doc = """If true, esbuild produces an output directory containing all the output files from code splitting for multiple entry points
233246
234- See https://esbuild.github.io/api/#splitting for more details
247+ See https://esbuild.github.io/api/#splitting and https://esbuild.github.io/api/#entry-points for more details
235248 """ ,
236249 ),
237250 "output_map" : attr .output (
@@ -308,7 +321,8 @@ def esbuild_macro(name, output_dir = False, **kwargs):
308321 entry_point = Label ("@build_bazel_rules_nodejs//packages/esbuild:launcher.js" ),
309322 )
310323
311- if output_dir == True :
324+ entry_points = kwargs .get ("entry_points" , None )
325+ if output_dir == True or entry_points :
312326 esbuild (
313327 name = name ,
314328 output_dir = True ,
0 commit comments