blob: f458dfba61611e8cda7f50e47a48b297da86e7cb [file] [log] [blame] [edit]
<!DOCTYPE html>
<html itemscope itemtype="https://schema.org/WebPage" lang="en">
<head>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="/rules_nodejs/Rollup.html" rel="canonical">
<link href="" rel="shortcut icon" type="image/png">
<title>rules_nodejs - Rollup</title>
<!-- Webfont -->
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro:400,500,700|Open+Sans:400,600,700,800" rel="stylesheet">
<!-- Bootstrap -->
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Custom stylesheet -->
<link href="/rules_nodejs/css/main.css" rel="stylesheet">
<!-- metadata -->
<meta content="rules_nodejs" name="og:title"/>
<meta content="JavaScript and NodeJS rules for Bazel" name="og:description"/>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id="common-nav">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button class="navbar-toggle collapsed" data-target="#bs-example-navbar-collapse-1" data-toggle="collapse"
type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/rules_nodejs/">
<img class="navbar-logo" src="/rules_nodejs/images/bazel-navbar.svg">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-right" action="/rules_nodejs/search.html" id="cse-search-box">
<div class="form-group">
<input type="hidden" name="cx" value="2735dc72dd157bd19">
<input type="search" name="q" id="q" class="form-control input-sm" placeholder="Search">
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/bazelbuild/rules_nodejs">GitHub</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container vpad">
<div class="row">
<div class="col-md-2">
<a aria-controls="sidebar-nav"
aria-expanded="false" class="btn btn-default btn-lg btn-block sidebar-toggle" data-toggle="collapse"
href="#sidebar-nav">
<i class="glyphicon glyphicon-menu-hamburger"></i> Navigation
</a>
<nav class="sidebar collapse" id="sidebar-nav">
<h3>rules_nodejs</h3>
<ul class="sidebar-nav">
<li><a href="/rules_nodejs/">Introduction</a></li>
<li><a href="install.html">Installation</a></li>
<li><a href="repositories.html">Repositories</a></li>
<li><a href="dependencies.html">Dependencies</a></li>
<li><a href="debugging.html">Debugging</a></li>
<li><a href="stamping.html">Stamping</a></li>
<li><a href="changing-rules.html">Making changes to rules_nodejs</a></li>
<li><a href="examples.html">Examples</a></li>
</ul>
<h3>Rules</h3>
<ul class="sidebar-nav">
<li><a href="/rules_nodejs/Built-ins.html">Built-ins</a></li>
<li><a href="/rules_nodejs/Cypress.html">Cypress</a></li>
<li><a href="/rules_nodejs/Jasmine.html">Jasmine</a></li>
<li><a href="/rules_nodejs/Karma.html">Karma</a></li>
<li><a href="/rules_nodejs/Labs.html">Labs</a></li>
<li><a href="/rules_nodejs/Protractor.html">Protractor</a></li>
<li><a href="/rules_nodejs/Rollup.html">Rollup</a></li>
<li><a href="/rules_nodejs/Terser.html">Terser</a></li>
<li><a href="/rules_nodejs/TypeScript.html">TypeScript</a></li>
</ul>
<h3>Community</h3>
<ul class="sidebar-nav">
<li><a href="https://github.com/bazelbuild/rules_nodejs/blob/master/CONTRIBUTING.md">Contribute to
rules_nodejs</a></li>
<li><a href="https://slack.bazel.build">Join #javascript on Slack</a></li>
<li><a href="https://github.com/bazelbuild/rules_nodejs/issues">Issue Tracker</a></li>
<li><a href="https://github.com/bazelbuild/rules_nodejs">Github</a></li>
</ul>
</nav>
</div>
<div class="col-md-8">
<div class="content">
<!-- *********************
DO NOT EDIT THIS FILE
It is a generated build output from Stardoc.
Instead you must edit the .bzl file where the rules are declared,
or possibly a markdown file next to the .bzl file
********************* -->
<h1 id="rollup-rules-for-bazel">Rollup rules for Bazel</h1>
<p>The Rollup rules run the <a href="https://rollupjs.org/">rollup.js</a> bundler with Bazel.</p>
<h2 id="installation">Installation</h2>
<p>Add the <code class="language-plaintext highlighter-rouge">@bazel/rollup</code> npm package to your <code class="language-plaintext highlighter-rouge">devDependencies</code> in <code class="language-plaintext highlighter-rouge">package.json</code>.</p>
<h3 id="installing-with-self-managed-dependencies">Installing with self-managed dependencies</h3>
<p>If you didn’t use the <code class="language-plaintext highlighter-rouge">yarn_install</code> or <code class="language-plaintext highlighter-rouge">npm_install</code> rule, you’ll have to declare a rule in your root <code class="language-plaintext highlighter-rouge">BUILD.bazel</code> file to execute rollup:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Create a rollup rule to use in rollup_bundle#rollup_bin
# attribute when using self-managed dependencies
</span><span class="n">nodejs_binary</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"rollup_bin"</span><span class="p">,</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"//:node_modules/rollup/bin/rollup"</span><span class="p">,</span>
<span class="c1"># Point bazel to your node_modules to find the entry point
</span> <span class="n">node_modules</span> <span class="o">=</span> <span class="p">[</span><span class="s">"//:node_modules"</span><span class="p">],</span>
<span class="p">)</span>
</code></pre></div></div>
<h2 id="usage">Usage</h2>
<p>The <code class="language-plaintext highlighter-rouge">rollup_bundle</code> rule is used to invoke Rollup on some JavaScript inputs.
The API docs appear <a href="#rollup_bundle">below</a>.</p>
<p>Typical example:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">load</span><span class="p">(</span><span class="s">"@npm//@bazel/rollup:index.bzl"</span><span class="p">,</span> <span class="s">"rollup_bundle"</span><span class="p">)</span>
<span class="n">rollup_bundle</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"bundle"</span><span class="p">,</span>
<span class="n">srcs</span> <span class="o">=</span> <span class="p">[</span><span class="s">"dependency.js"</span><span class="p">],</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"input.js"</span><span class="p">,</span>
<span class="n">config_file</span> <span class="o">=</span> <span class="s">"rollup.config.js"</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div></div>
<p>Note that the command-line options set by Bazel override what appears in the rollup config file.
This means that typically a single <code class="language-plaintext highlighter-rouge">rollup.config.js</code> can contain settings for your whole repo,
and multiple <code class="language-plaintext highlighter-rouge">rollup_bundle</code> rules can share the configuration.</p>
<p>Thus, setting options that Bazel controls will have no effect, e.g.</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="p">{</span>
<span class="na">output</span><span class="p">:</span> <span class="p">{</span> <span class="na">file</span><span class="p">:</span> <span class="dl">'</span><span class="s1">this_is_ignored.js</span><span class="dl">'</span> <span class="p">},</span>
<span class="p">}</span>
</code></pre></div></div>
<h3 id="output-types">Output types</h3>
<p>You must determine ahead of time whether Rollup will write a single file or a directory.
Rollup’s CLI has the same behavior, forcing you to pick <code class="language-plaintext highlighter-rouge">--output.file</code> or <code class="language-plaintext highlighter-rouge">--output.dir</code>.</p>
<p>Writing a directory is used when you have dynamic imports which cause code-splitting, or if you
provide multiple entry points. Use the <code class="language-plaintext highlighter-rouge">output_dir</code> attribute to specify that you want a
directory output.</p>
<p>Each <code class="language-plaintext highlighter-rouge">rollup_bundle</code> rule produces only one output by running the rollup CLI a single time.
To get multiple output formats, you can wrap the rule with a macro or list comprehension, e.g.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span>
<span class="n">rollup_bundle</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"bundle.%s"</span> <span class="o">%</span> <span class="nb">format</span><span class="p">,</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"foo.js"</span><span class="p">,</span>
<span class="nb">format</span> <span class="o">=</span> <span class="nb">format</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">for</span> <span class="nb">format</span> <span class="ow">in</span> <span class="p">[</span>
<span class="s">"cjs"</span><span class="p">,</span>
<span class="s">"umd"</span><span class="p">,</span>
<span class="p">]</span>
<span class="p">]</span>
</code></pre></div></div>
<p>This will produce one output per requested format.</p>
<h3 id="stamping">Stamping</h3>
<p>You can stamp the current version control info into the output by writing some code in your rollup config.
See the <a href="stamping">stamping documentation</a>.</p>
<p>By passing the <code class="language-plaintext highlighter-rouge">--stamp</code> option to Bazel, two additional input files will be readable by Rollup.</p>
<ol>
<li>The variable <code class="language-plaintext highlighter-rouge">bazel_version_file</code> will point to <code class="language-plaintext highlighter-rouge">bazel-out/volatile-status.txt</code> which contains
statuses that change frequently; such changes do not cause a re-build of the rollup_bundle.</li>
<li>The variable <code class="language-plaintext highlighter-rouge">bazel_info_file</code> will point to <code class="language-plaintext highlighter-rouge">bazel-out/stable-status.txt</code> file which contains
statuses that stay the same; any changed values will cause rollup_bundle to rebuild.</li>
</ol>
<p>Both <code class="language-plaintext highlighter-rouge">bazel_version_file</code> and <code class="language-plaintext highlighter-rouge">bazel_info_file</code> will be <code class="language-plaintext highlighter-rouge">undefined</code> if the build is run without <code class="language-plaintext highlighter-rouge">--stamp</code>.</p>
<blockquote>
<p>Note that under <code class="language-plaintext highlighter-rouge">--stamp</code>, only the bundle is re-built, but not the compilation steps that produced the inputs.
This avoids a slow cascading re-build of a whole tree of actions.</p>
</blockquote>
<p>To use these files, you write JS code in your <code class="language-plaintext highlighter-rouge">rollup.config.js</code> to read from the status files and parse the lines.
Each line is a space-separated key/value pair.</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Parse the stamp file produced by Bazel from the version control system</span>
<span class="kd">let</span> <span class="nx">version</span> <span class="o">=</span> <span class="dl">'</span><span class="s1">&lt;unknown&gt;</span><span class="dl">'</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">bazel_info_file</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">const</span> <span class="nx">versionTag</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">fs</span><span class="dl">'</span><span class="p">)</span>
<span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">bazel_info_file</span><span class="p">,</span> <span class="p">{</span><span class="na">encoding</span><span class="p">:</span> <span class="dl">'</span><span class="s1">utf-8</span><span class="dl">'</span><span class="p">})</span>
<span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="dl">'</span><span class="se">\n</span><span class="dl">'</span><span class="p">)</span>
<span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">s</span> <span class="o">=&gt;</span> <span class="nx">s</span><span class="p">.</span><span class="nx">startsWith</span><span class="p">(</span><span class="dl">'</span><span class="s1">STABLE_GIT_COMMIT</span><span class="dl">'</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">versionTag</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">version</span> <span class="o">=</span> <span class="dl">'</span><span class="s1">v</span><span class="dl">'</span> <span class="o">+</span> <span class="nx">versionTag</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="dl">'</span><span class="s1"> </span><span class="dl">'</span><span class="p">)[</span><span class="mi">1</span><span class="p">].</span><span class="nx">trim</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<h3 id="debug-and-opt-builds">Debug and Opt builds</h3>
<p>When you use <code class="language-plaintext highlighter-rouge">--compilation_mode=dbg</code>, Bazel produces a distinct output-tree in <code class="language-plaintext highlighter-rouge">bazel-out/[arch]-dbg/bin</code>.
Code in your <code class="language-plaintext highlighter-rouge">rollup.config.js</code> can look in the environment to detect if a debug build is being performed,
and include extra developer information in the bundle that you wouldn’t normally ship to production.</p>
<p>Similarly, <code class="language-plaintext highlighter-rouge">--compilation_mode=opt</code> is Bazel’s signal to perform extra optimizations.
You could use this value to perform extra production-only optimizations.</p>
<p>For example you could define a constant for enabling Debug:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">DEBUG</span> <span class="o">=</span> <span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">[</span><span class="dl">'</span><span class="s1">COMPILATION_MODE</span><span class="dl">'</span><span class="p">]</span> <span class="o">===</span> <span class="dl">'</span><span class="s1">dbg</span><span class="dl">'</span><span class="p">;</span>
</code></pre></div></div>
<p>and configure Rollup differently when <code class="language-plaintext highlighter-rouge">DEBUG</code> is <code class="language-plaintext highlighter-rouge">true</code> or <code class="language-plaintext highlighter-rouge">false</code>.</p>
<h3 id="increasing-heap-memory-for-rollup">Increasing Heap memory for rollup</h3>
<p>The <code class="language-plaintext highlighter-rouge">rollup_bin</code> attribute allows you to customize the rollup.js program we execute,
so you can use <code class="language-plaintext highlighter-rouge">nodejs_binary</code> to construct your own.</p>
<blockquote>
<p>You can always call <code class="language-plaintext highlighter-rouge">bazel query --output=build [default rollup_bin]</code> to see what
the default definition looks like, then copy-paste from there to be sure yours
matches.</p>
</blockquote>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">nodejs_binary</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"rollup_more_mem"</span><span class="p">,</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="s">"@npm//rollup:rollup"</span><span class="p">],</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"@npm//:node_modules/rollup/dist/bin/rollup"</span><span class="p">,</span>
<span class="n">templated_args</span> <span class="o">=</span> <span class="p">[</span>
<span class="s">"--nobazel_patch_module_resolver"</span><span class="p">,</span>
<span class="s">"--node_options=--max-old-space-size=&lt;SOME_SIZE&gt;"</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
<span class="n">rollup_bundle</span><span class="p">(</span>
<span class="p">...</span>
<span class="n">rollup_bin</span> <span class="o">=</span> <span class="s">":rollup_more_mem"</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div></div>
<h2 id="rollup_bundle">rollup_bundle</h2>
<p><strong>USAGE</strong></p>
<pre>
rollup_bundle(<a href="#rollup_bundle-name">name</a>, <a href="#rollup_bundle-args">args</a>, <a href="#rollup_bundle-config_file">config_file</a>, <a href="#rollup_bundle-deps">deps</a>, <a href="#rollup_bundle-entry_point">entry_point</a>, <a href="#rollup_bundle-entry_points">entry_points</a>, <a href="#rollup_bundle-format">format</a>, <a href="#rollup_bundle-link_workspace_root">link_workspace_root</a>,
<a href="#rollup_bundle-node_context_data">node_context_data</a>, <a href="#rollup_bundle-output_dir">output_dir</a>, <a href="#rollup_bundle-rollup_bin">rollup_bin</a>, <a href="#rollup_bundle-rollup_worker_bin">rollup_worker_bin</a>, <a href="#rollup_bundle-silent">silent</a>, <a href="#rollup_bundle-sourcemap">sourcemap</a>, <a href="#rollup_bundle-srcs">srcs</a>,
<a href="#rollup_bundle-supports_workers">supports_workers</a>)
</pre>
<p>Runs the rollup.js CLI under Bazel.</p>
<p><strong>ATTRIBUTES</strong></p>
<h4 id="rollup_bundle-name">name</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#name">Name</a>, mandatory</em>): A unique name for this target.</p>
<h4 id="rollup_bundle-args">args</h4>
<p>(<em>List of strings</em>): Command line arguments to pass to Rollup. Can be used to override config file settings.</p>
<p>These argument passed on the command line before arguments that are added by the rule.
Run <code class="language-plaintext highlighter-rouge">bazel</code> with <code class="language-plaintext highlighter-rouge">--subcommands</code> to see what Rollup CLI command line was invoked.</p>
<p>See the <a href="https://rollupjs.org/guide/en/#command-line-flags">Rollup CLI docs</a> for a complete list of supported arguments.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">[]</code></p>
<h4 id="rollup_bundle-config_file">config_file</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">Label</a></em>): A <code class="language-plaintext highlighter-rouge">rollup.config.js</code> file</p>
<p>Passed to the <code class="language-plaintext highlighter-rouge">--config</code> option, see <a href="https://rollupjs.org/guide/en/#configuration-files">the config doc</a></p>
<p>If not set, a default basic Rollup config is used.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">@npm//@bazel/rollup:rollup.config.js</code></p>
<h4 id="rollup_bundle-deps">deps</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a></em>): Other libraries that are required by the code, or by the rollup.config.js</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">[]</code></p>
<h4 id="rollup_bundle-entry_point">entry_point</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">Label</a></em>): The bundle’s entry point (e.g. your main.js or app.js or index.js).</p>
<p>This is just a shortcut for the <code class="language-plaintext highlighter-rouge">entry_points</code> attribute with a single output chunk named the same as the rule.</p>
<p>For example, these are equivalent:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">rollup_bundle</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"bundle"</span><span class="p">,</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"index.js"</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div></div>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">rollup_bundle</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"bundle"</span><span class="p">,</span>
<span class="n">entry_points</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">"index.js"</span><span class="p">:</span> <span class="s">"bundle"</span>
<span class="p">}</span>
<span class="p">)</span>
</code></pre></div></div>
<p>If <code class="language-plaintext highlighter-rouge">rollup_bundle</code> is used on a <code class="language-plaintext highlighter-rouge">ts_library</code>, the <code class="language-plaintext highlighter-rouge">rollup_bundle</code> rule handles selecting the correct outputs from <code class="language-plaintext highlighter-rouge">ts_library</code>.
In this case, <code class="language-plaintext highlighter-rouge">entry_point</code> can be specified as the <code class="language-plaintext highlighter-rouge">.ts</code> file and <code class="language-plaintext highlighter-rouge">rollup_bundle</code> will handle the mapping to the <code class="language-plaintext highlighter-rouge">.mjs</code> output file.</p>
<p>For example:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">ts_library</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"foo"</span><span class="p">,</span>
<span class="n">srcs</span> <span class="o">=</span> <span class="p">[</span>
<span class="s">"foo.ts"</span><span class="p">,</span>
<span class="s">"index.ts"</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
<span class="n">rollup_bundle</span><span class="p">(</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">"bundle"</span><span class="p">,</span>
<span class="n">deps</span> <span class="o">=</span> <span class="p">[</span> <span class="s">"foo"</span> <span class="p">],</span>
<span class="n">entry_point</span> <span class="o">=</span> <span class="s">"index.ts"</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div></div>
<p>Defaults to <code class="language-plaintext highlighter-rouge">None</code></p>
<h4 id="rollup_bundle-entry_points">entry_points</h4>
<p>(<em><a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: Label -&gt; String</a></em>): The bundle’s entry points (e.g. your main.js or app.js or index.js).</p>
<p>Passed to the <a href="https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#input"><code class="language-plaintext highlighter-rouge">--input</code> option</a> in Rollup.</p>
<p>Keys in this dictionary are labels pointing to .js entry point files.
Values are the name to be given to the corresponding output chunk.</p>
<p>Either this attribute or <code class="language-plaintext highlighter-rouge">entry_point</code> must be specified, but not both.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">{}</code></p>
<h4 id="rollup_bundle-format">format</h4>
<p>(<em>String</em>): Specifies the format of the generated bundle. One of the following:</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">amd</code>: Asynchronous Module Definition, used with module loaders like RequireJS</li>
<li><code class="language-plaintext highlighter-rouge">cjs</code>: CommonJS, suitable for Node and other bundlers</li>
<li><code class="language-plaintext highlighter-rouge">esm</code>: Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a <code class="language-plaintext highlighter-rouge">&lt;script type=module&gt;</code> tag in modern browsers</li>
<li><code class="language-plaintext highlighter-rouge">iife</code>: A self-executing function, suitable for inclusion as a <code class="language-plaintext highlighter-rouge">&lt;script&gt;</code> tag. (If you want to create a bundle for your application, you probably want to use this.)</li>
<li><code class="language-plaintext highlighter-rouge">umd</code>: Universal Module Definition, works as amd, cjs and iife all in one</li>
<li><code class="language-plaintext highlighter-rouge">system</code>: Native format of the SystemJS loader</li>
</ul>
<p>Defaults to <code class="language-plaintext highlighter-rouge">"esm"</code></p>
<h4 id="rollup_bundle-link_workspace_root">link_workspace_root</h4>
<p>(<em>Boolean</em>): Link the workspace root to the bin_dir to support absolute requires like ‘my_wksp/path/to/file’.
If source files need to be required then they can be copied to the bin_dir with copy_to_bin.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">False</code></p>
<h4 id="rollup_bundle-node_context_data">node_context_data</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">Label</a></em>): Provides info about the build context, such as stamping.</p>
<p>By default it reads from the bazel command line, such as the <code class="language-plaintext highlighter-rouge">--stamp</code> argument.
Use this to override values for this target, such as enabling or disabling stamping.
You can use the <code class="language-plaintext highlighter-rouge">node_context_data</code> rule in <code class="language-plaintext highlighter-rouge">@build_bazel_rules_nodejs//internal/node:context.bzl</code>
to create a NodeContextInfo. The dependencies of this attribute must provide: NodeContextInfo</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">@build_bazel_rules_nodejs//internal:node_context_data</code></p>
<h4 id="rollup_bundle-output_dir">output_dir</h4>
<p>(<em>Boolean</em>): Whether to produce a directory output.</p>
<p>We will use the <a href="https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#outputdir"><code class="language-plaintext highlighter-rouge">--output.dir</code> option</a> in rollup
rather than <code class="language-plaintext highlighter-rouge">--output.file</code>.</p>
<p>If the program produces multiple chunks, you must specify this attribute.
Otherwise, the outputs are assumed to be a single file.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">False</code></p>
<h4 id="rollup_bundle-rollup_bin">rollup_bin</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">Label</a></em>): Target that executes the rollup binary</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">@npm//rollup/bin:rollup</code></p>
<h4 id="rollup_bundle-rollup_worker_bin">rollup_worker_bin</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">Label</a></em>): Internal use only</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">@npm//@bazel/bin:rollup-worker</code></p>
<h4 id="rollup_bundle-silent">silent</h4>
<p>(<em>Boolean</em>): Whether to execute the rollup binary with the –silent flag, defaults to False.</p>
<p>Using –silent can cause rollup to <a href="https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#onwarn">ignore errors/warnings</a>
which are only surfaced via logging. Since bazel expects printing nothing on success, setting silent to True
is a more Bazel-idiomatic experience, however could cause rollup to drop important warnings.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">False</code></p>
<h4 id="rollup_bundle-sourcemap">sourcemap</h4>
<p>(<em>String</em>): Whether to produce sourcemaps.</p>
<p>Passed to the <a href="https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#outputsourcemap&quot;"><code class="language-plaintext highlighter-rouge">--sourcemap</code> option</a> in Rollup</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">"inline"</code></p>
<h4 id="rollup_bundle-srcs">srcs</h4>
<p>(<em><a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a></em>): Non-entry point JavaScript source files from the workspace.</p>
<p>You must not repeat file(s) passed to entry_point/entry_points.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">[]</code></p>
<h4 id="rollup_bundle-supports_workers">supports_workers</h4>
<p>(<em>Boolean</em>): Experimental! Use only with caution.</p>
<p>Allows you to enable the Bazel Worker strategy for this library.
When enabled, this rule invokes the “rollup_worker_bin”
worker aware binary rather than “rollup_bin”.</p>
<p>Defaults to <code class="language-plaintext highlighter-rouge">False</code></p>
</div>
</div>
<div class="col-md-2 sticky-sidebar">
<div class="right-sidebar">
<ul class="gh-links">
<li>
<i class="fa fa-github"></i>
<a href="https://github.com/bazelbuild/rules_nodejs/issues/new?title=Documentation issue: Rollup&labels=question/docs">Create
issue</a>
</li>
</ul>
<ul class="section-nav">
<li class="toc-entry toc-h2"><a href="#installation">Installation</a>
<ul>
<li class="toc-entry toc-h3"><a href="#installing-with-self-managed-dependencies">Installing with self-managed dependencies</a></li>
</ul>
</li>
<li class="toc-entry toc-h2"><a href="#usage">Usage</a>
<ul>
<li class="toc-entry toc-h3"><a href="#output-types">Output types</a></li>
<li class="toc-entry toc-h3"><a href="#stamping">Stamping</a></li>
<li class="toc-entry toc-h3"><a href="#debug-and-opt-builds">Debug and Opt builds</a></li>
<li class="toc-entry toc-h3"><a href="#increasing-heap-memory-for-rollup">Increasing Heap memory for rollup</a></li>
</ul>
</li>
<li class="toc-entry toc-h2"><a href="#rollup_bundle">rollup_bundle</a></li>
</ul>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="col-lg-8">
<p class="text-muted">&copy; 2020 The rules_nodejs authors</p>
</div>
</div>
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script crossorigin="anonymous"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Anchor JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/3.2.0/anchor.min.js" type="text/javascript"></script>
<script>
// Automatically add anchors and links to all header elements that don't already have them.
anchors.options = { placement: 'left' };
anchors.add();
</script>
<script>
var shiftWindow = function () {
if (location.hash.length !== 0) {
window.scrollBy(0, -50);
}
};
window.addEventListener("hashchange", shiftWindow);
var highlightCurrentSidebarNav = function () {
var href = location.pathname;
var item = $('#sidebar-nav [href$="' + href + '"]');
if (item) {
var li = item.parent();
li.addClass("active");
if (li.parent() && li.parent().is("ul")) {
do {
var ul = li.parent();
if (ul.hasClass("collapse")) {
ul.collapse("show");
}
li = ul.parent();
} while (li && li.is("li"));
}
}
};
$(document).ready(function () {
// Scroll to anchor of location hash, adjusted for fixed navbar.
window.setTimeout(function () {
shiftWindow();
}, 1);
// Flip the caret when submenu toggles are clicked.
$(".sidebar-submenu").on("show.bs.collapse", function () {
var toggle = $('[href$="#' + $(this).attr('id') + '"]');
if (toggle) {
toggle.addClass("dropup");
}
});
$(".sidebar-submenu").on("hide.bs.collapse", function () {
var toggle = $('[href$="#' + $(this).attr('id') + '"]');
if (toggle) {
toggle.removeClass("dropup");
}
});
// Highlight the current page on the sidebar nav.
highlightCurrentSidebarNav();
});
</script>
</body>
</html>