djblets.pipeline.settings¶
Utilities and constants for configuring Pipeline.
Note
This is safe to import from a project’s settings.py without
side effects (for instance, it will not load any Django models or apps).
New in version 2.1.
- DEFAULT_PIPELINE_COMPILERS: list[str] = ['djblets.pipeline.compilers.es6.ES6Compiler', 'djblets.pipeline.compilers.typescript.TypeScriptCompiler', 'djblets.pipeline.compilers.less.LessCompiler']¶
Default list of compilers used by Djblets.
- build_pipeline_settings(*, pipeline_enabled: bool, node_modules_path: str, static_root: str, javascript_bundles: Mapping[str, StaticBundle] | None = None, stylesheet_bundles: Mapping[str, StaticBundle] | None = None, compilers: list[str] = ['djblets.pipeline.compilers.es6.ES6Compiler', 'djblets.pipeline.compilers.typescript.TypeScriptCompiler', 'djblets.pipeline.compilers.less.LessCompiler'], babel_extra_plugins: Sequence[str] | None = None, babel_extra_args: Sequence[str] | None = None, less_extra_args: Sequence[str] | None = None, validate_paths: bool = True, use_rollup: bool = True, rollup_extra_args: Sequence[str] | None = None, extra_config: Mapping[str, Any] | None = None, use_terser: bool = False) dict[str, Any][source]¶
Build a standard set of Pipeline settings.
This can be used to create a
PIPELINEsettings dictionary in asettings.pyfile based on the standard Djblets Pipeline settings.By default, this makes use of Babel, LessCSS, and UglifyJS, along with a preset list of plugins.
The following base set of Babel plugins are used:
The following LessCSS plugin is used:
Optionally, rollup.js <https://www.rollupjs.org> can be used by setting
use_rollup=True. This will make use ofdjblets.pipeline.rollup.RollupCompiler, configuring it to automatically compile any of the following files:index.jsindex.es6,index.es6.jsindex.ts
These modules can make use of modern JavaScript
import/exportstatements. Any relatively-imported modules will be rolled up during compilation for theindexfile.Note
These files should not be specified as part of the Pipeline bundle! Rollup will instead bundle them into the compiled index file.
As a convenience, this function will also set the value of
node_modules_pathin theNODE_PATHenvironment variable.Changed in version 6.0:
Changed to support a colon-separated list for the
node_modules_pathargument.Added support for terser <https://terser.org>.
Added the
use_terserargument.
Changed in version 4.0:
Added support for rollup.js <https://www.rollupjs.org>.
Added
extra_config,use_rollup`, and ``rollup_extra_argsparameters.
- Parameters:
pipeline_enabled (
bool) –Whether Pipelining of static media should be enabled.
This must be provided by a caller. It’s recommended to enable this if
DEBUGisFalse(or, better, use another variable indicating a production vs. development environment).node_modules_path (
str) –A colon-separated list of paths to
node_modulesdirectories.If
validate_paths=False, it’s up to the caller to ensure that the the first path in the list refers to anode_modulesdirectory that exists and contains the required binaries at build time.static_root (
str) – The value of thesettings.STATIC_ROOT. This must be provided explicitly, sincesettings.pyis likely the module calling this.javascript_bundles (
listofdict, optional) – A list of JavaScript bundle packages for Pipeline to handle.stylesheet_bundles (
listofdict, optional) – A list of stylesheet bundle packages for Pipeline to handle.compilers (
listofstr, optional) – A list of compilers to use for static media.babel_extra_plugins (
listofstr, optional) – A list of additional Babel plugins to enable.babel_extra_args (
listofstr, optional) – Extra command line arguments to pass to Babel.less_extra_args (
listofstr, optional) – Extra command line arguments to pass to LessCSS.validate_paths (
bool, optional) –Whether to validate any expected paths to binaries.
It’s recommended to set this based on
DEBUG, or another variable indicating a production vs. development environment. It should beFalsewhen binaries may not exist at call time of this function, but will exist later at build time.If the
DJBLETS_SKIP_PIPELINE_VALIDATIONenvironment variable is set to1, then this will be forced toFalse. This is primarily used for packaging building.use_rollup (
bool, optional) –Whether to use rollup to assemble JavaScript bundles.
New in version 4.0.
rollup_extra_args (
listofstr, optional) –Extra command line arguments to pass to rollup.
New in version 4.0.
extra_config (
dict, optional) –Additional configuration to merge into the resulting dictionary.
New in version 4.0.
use_terser (
bool, optional) –Whether to use Terser instead of UglifyJS.
New in version 6.0.
- Returns:
The pipeline configuration dictionary.
- Return type:
- find_node_modules_dirs(directory: str | Path) Iterator[Path][source]¶
Find and return all
node_modulesdirectories above a given path.New in version 6.0.
- Parameters:
directory (
strorpathlib.Path) – The directory to search from.- Yields:
listofpathlib.Path– A list of all existingnode_modulesdirectories which are found at or above the given directory.