API Docs

Manifests

Webpack manifests API.

exception pywebpack.manifests.InvalidManifestError[source]

Invalid manifest.

class pywebpack.manifests.Manifest[source]

Assets manifest.

Initialize manifest.

add(entry)[source]

Add an entry to the manifest.

class pywebpack.manifests.ManifestEntry(name, paths)[source]

Represents a manifest entry.

Initialize manifest entry.

render()[source]

Render entry.

exception pywebpack.manifests.ManifestError[source]

Manifest error.

class pywebpack.manifests.ManifestFactory(manifest_cls=<class 'pywebpack.manifests.Manifest'>, entry_cls=<class 'pywebpack.manifests.ManifestEntry'>)[source]

Manifest factory base class.

Initialize factory.

create_entry(entry, paths)[source]

Create a manifest entry instance.

create_manifest()[source]

Create a manifest instance.

load(filepath)[source]

Load a manifest file.

class pywebpack.manifests.ManifestLoader(manifest_cls=<class 'pywebpack.manifests.Manifest'>, entry_cls=<class 'pywebpack.manifests.ManifestEntry'>)[source]

Loads a Webpack manifest (multiple types supported).

Initialize loader.

load(filepath)[source]

Load a manifest from a file.

exception pywebpack.manifests.UnfinishedManifestError[source]

Manifest is currently being built.

exception pywebpack.manifests.UnsupportedExtensionError[source]

Manifest contains a file with an extension that is not supported.

exception pywebpack.manifests.UnsupportedManifestError[source]

Could not parse the manifest.

class pywebpack.manifests.WebpackBundleTrackerFactory(manifest_cls=<class 'pywebpack.manifests.Manifest'>, entry_cls=<class 'pywebpack.manifests.ManifestEntry'>)[source]

Manifest factory for webpack-bundle-tracker.

Initialize factory.

create(data)[source]

Create manifest from parsed data.

class pywebpack.manifests.WebpackManifestFactory(manifest_cls=<class 'pywebpack.manifests.Manifest'>, entry_cls=<class 'pywebpack.manifests.ManifestEntry'>)[source]

Manifest factory for webpack-manifest-plugin.

Initialize factory.

create(data)[source]

Create manifest from parsed data.

class pywebpack.manifests.WebpackYamFactory(manifest_cls=<class 'pywebpack.manifests.Manifest'>, entry_cls=<class 'pywebpack.manifests.ManifestEntry'>)[source]

Manifest factory for webpack-yam-plugin.

Initialize factory.

create(data)[source]

Create manifest from parsed data.

Projects

API for creating and building Webpack projects.

class pywebpack.project.WebpackBundleProject(working_dir, project_template_dir, bundles=None, config=None, config_path=None, storage_cls=None, package_json_source_path='package.json')[source]

Build webpack project from multiple bundles.

Initialize templated folder.

Parameters
  • working_dir – Path where config and assets files will be copied.

  • project_template_dir – Absolute path to the project folder.

  • bundles – List of pywebpack.bundle.WebpackBundle. This list can be statically defined if the bundles are known before hand, or dinamically generated using pywebpack.helpers.bundles_from_entry_point() so the bundles are discovered from the defined Webpack entrypoints exposed by other modules.

  • config – Dictionary used to create the config.json file generated by pywebpack. It adds extra configuration at build time.

  • config_path – Path in working_dir where config.json will be written.

  • storage_cls – Storage class.

  • package_json_source_path – Path relative to project_template_dir to the project’s package.json.

property aliases

Get webpack resolver aliases from bundles.

property bundles

Get bundles.

collect(force=None)[source]

Collect asset files from bundles.

property config

Inject webpack entry points from bundles.

create(force=None)[source]

Create webpack project from a template.

This command collects all asset files from the bundles. It generates a new package.json by merging the package.json dependencies of each bundle.

property dependencies

Get package.json dependencies.

property entry

Get webpack entry points.

property package_json

Merge bundle dependencies into package.json.

property package_json_source

Read original package.json contents.

property package_json_source_path

Full path to the source package.json.

class pywebpack.project.WebpackProject(path)[source]

API for building an existing Webpack project.

Initialize instance.

build(*args)[source]

Run build script.

buildall()[source]

Build project from scratch.

install(*args)[source]

Install project.

property npmpkg

Get API to NPM package.

property path

Path property.

property project_path

Get the project path.

run(script_name, *args)[source]

Run an NPM script.

class pywebpack.project.WebpackTemplateProject(working_dir, project_template_dir, config=None, config_path=None, storage_cls=None)[source]

API for creating and building a webpack project based on a template.

Copies all files from a project template folder into a destination path and optionally writes a user provided config in JSON into the destination path as well.

Initialize templated folder.

Parameters
  • working_dir – Path where config and assets files will be copied.

  • project_template_dir – absolute path to the project folder.

  • config – Dictionary used to create the config.json file generated by pywebpack. It adds extra configuration at build time.

  • config_path – Path in working_dir where config.json will be written.

  • storage_cls – Storage class.

buildall()[source]

Build project from scratch.

clean()[source]

Clean created webpack project.

property config

Get configuration dictionary.

property config_path

Get configuration path.

create(force=None, skip=None)[source]

Create webpack project from a template.

property storage_cls

Storage class property.

Bundles

Webpack bundle API.

class pywebpack.bundle.WebpackBundle(path, entry=None, dependencies=None, devDependencies=None, peerDependencies=None, aliases=None)[source]

Webpack bundle.

Initialize webpack bundle.

Parameters
  • path – Absolute path to the folder where the assets are located.

  • entry – webpack entry; it indicates which modules webpack should use to begin building out its internal dependency graph.

  • dependencies – npm dependencies.

  • devDependencies – npm dev dependencies.

  • peerDependencies – npm peer dependencies.

  • aliases – Webpack resolver aliases.

Helpers

Webpack bundle API.

pywebpack.helpers.bundles_from_entry_point(group)[source]

Load bundles from entry point group.

pywebpack.helpers.cached(f)[source]

Decorator to cache result of property.

pywebpack.helpers.check_exit(f)[source]

Decorator to ensure that an NPM process exited successfully.

pywebpack.helpers.merge_deps(deps, bundles_deps)[source]

Merge NPM dependencies.

Storage

Storage API.

class pywebpack.storage.FileStorage(srcdir, dstdir, **kwargs)[source]

Storage class that copies files if source is newer than destination.

Initialize storage.

run(force=None, skip=None)[source]

Copy files from source to destination.

class pywebpack.storage.LinkStorage(*args, **kwargs)[source]

Storage class that link files.

Initialize storage.

pywebpack.storage.iter_files(folder)[source]

Iterate all files in a given root directory.

pywebpack.storage.iter_paths(folder, root=None, depth=None)[source]

Recursively yields paths under a folder up to a maximum depth.