djblets.pipeline.compilers.rollup¶
Pipeline compiler for bundling modern JavaScript with rollup.js.
New in version 4.0.
- DEFAULT_FILE_PATTERN = 'index\\.(js|es6|es6\\.js|ts)$'¶
The default regular expression used for rollup.js index files.
New in version 4.0.
- class RollupCompiler(verbose, storage)¶
Bases:
SourceMapStaleCheckMixin
,SubProcessCompiler
A Pipeline compiler for interfacing with rollup.js.
rollup.js is a module bundler for JavaScript that compiles down a JavaScript codebase, linked together through module imports (ES6, CommonJS etc.), into a single JavaScript file. It can manage compilation with Babel or TypeScript, and supports a wide variety of plugins.
This compiler makes it easy to develop modern JavaScript while still taking advantage of the best of Pipeline, such as managing separate bundles, loading bundles into Django templates, and triggering automatic recompilation on demand if any files (including those imported via modules) in the bundle are stale.
To use this compiler, you will need an
index
file in your Pipeline JavaScript bundle, which imports any other modules that should be part of that compiled rollup.js bundle. Anindex
file can be in the following forms:index.js
index.es6
index.es6.js
index.ts
Custom filename patterns can be specified by setting
settings.PIPELINE['ROLLUP_FILE_PATTERN']
to a regular expression string (defaults toDEFAULT_FILE_PATTERN
).Your Pipeline bundle may consist of just this one
index
file, or it may include other JavaScript as well. Eachindex
will be compiled as its own rollup.js bundle, and its compiled contents included as part of the Pipeline bundle.Sourcemaps are used to check if any parts of the bundle are stale, triggering automatic recompilation when loading pages. Please note that any modules that you want included but are not actively being used within that rollup.js bundle may be excluded from automatic recompilation detection if you have treeshaking enabled (which is enabled by default).
You will need to set
settings.PIPELINE['ROLLUP_BINARY']
to the path ofrollup
and then set any command line arguments needed (such as a path to your configuration file) insettings.PIPELINE['ROLLUP_ARGUMENTS']
.The arguments should not include
-c
/--config
to specify the Rollup configuration path. This will be computed automatically, in order to ensure the right file is used based on whichever source tree may be hosting the input file (such as when a project is consuming another project’s source files and compiling them).Changed in version 4.1: Added support for
rollup.config.mjs
androllup.config.ts
files.New in version 4.0.
- output_extension = 'js'¶
- match_file(path: str) bool ¶
Return whether this compiler matches a source file.
This will look for the following filenames by default:
index.js
index.es6
index.es6.js
index.ts
To customize this, set
settings.PIPELINE['ROLLUP_FILE_PATTERN']
to a regular expression string.
- compile_file(infile: str, outfile: str, outdated: bool = False, force: bool = False) None ¶
Compile a file using rollup.js.
This will cause the file and anything it imports in the tree into a rollup.js bundle, for inclusion in the Pipeline bundle.
- __annotations__ = {'_SOURCES_CACHE_TIME_SECS': 'int'}¶