polymer-bundler

  • Version 4.0.10
  • Published
  • 347 kB
  • 17 dependencies
  • BSD-3-Clause license

Install

npm i polymer-bundler
yarn add polymer-bundler
pnpm add polymer-bundler

Overview

Process Web Components into one output file

Index

Variables

variable bundleTypeExtnames

const bundleTypeExtnames: Map<BundleType, string>;

    Functions

    function composeStrategies

    composeStrategies: (strategies: BundleStrategy[]) => BundleStrategy;
    • Chains multiple bundle strategy functions together so the output of one becomes the input of the next and so-on.

    function generateBundles

    generateBundles: (depsIndex: TransitiveDependenciesMap) => Bundle[];
    • Given an index of files and their dependencies, produce an array of bundles, where a bundle is defined for each set of dependencies.

      For example, a dependency index representing the graph: a->b, b->c, b->d, e->c, e->f

      Would produce an array of three bundles: [a]->[a,b,d], [e]->[e,f], [a,e]->[c]

    function generateCountingSharedBundleUrlMapper

    generateCountingSharedBundleUrlMapper: (
    urlPrefix: ResolvedUrl
    ) => BundleUrlMapper;
    • Creates a bundle URL mapper function which takes a prefix and appends an incrementing value, starting with 1 to the filename.

    function generateEagerMergeStrategy

    generateEagerMergeStrategy: (entrypoint: ResolvedUrl) => BundleStrategy;
    • Generates a strategy function which finds all non-entrypoint bundles which are dependencies of the given entrypoint and merges them into that entrypoint's bundle.

    function generateMatchMergeStrategy

    generateMatchMergeStrategy: (
    predicate: (b: Bundle) => boolean
    ) => BundleStrategy;
    • Generates a strategy function which finds all bundles matching the predicate function and merges them into the bundle containing the target file.

    function generateNoBackLinkStrategy

    generateNoBackLinkStrategy: (urls: ResolvedUrl[]) => BundleStrategy;
    • Generates a strategy function that ensures bundles do not link to given URLs. Bundles which contain matching files will still have them inlined.

    function generateSharedBundleUrlMapper

    generateSharedBundleUrlMapper: (
    mapper: (sharedBundles: Bundle[]) => ResolvedUrl[]
    ) => BundleUrlMapper;
    • Creates a bundle URL mapper function which maps non-shared bundles to the URLs of their single entrypoint and yields responsibility for naming remaining shared bundle URLs to the mapper function argument. The mapper function takes a collection of shared bundles and a URL map, calling .set(url, bundle) for each.

    function generateSharedDepsMergeStrategy

    generateSharedDepsMergeStrategy: (
    maybeMinEntrypoints?: number
    ) => BundleStrategy;
    • Generates a strategy function to merge all bundles where the dependencies for a bundle are shared by at least 2 entrypoints (default; set minEntrypoints to change threshold).

      This function will convert an array of 4 bundles: [a]->[a,b], [a,c]->[d], [c]->[c,e], [f,g]->[f,g,h]

      Into the following 3 bundles, including a single bundle for all of the dependencies which are shared by at least 2 entrypoints: [a]->[a,b], [c]->[c,e], [a,c,f,g]->[d,f,g,h]

    function generateShellMergeStrategy

    generateShellMergeStrategy: (
    shell: ResolvedUrl,
    maybeMinEntrypoints?: number
    ) => BundleStrategy;
    • A bundle strategy function which merges all shared dependencies into a bundle for an application shell.

    function mergeBundles

    mergeBundles: (bundles: Bundle[], ignoreTypeCheck?: boolean) => Bundle;
    • Given an Array of bundles, produce a single bundle with the entrypoints and files of all bundles represented. By default, bundles of different types can not be merged, but this constraint can be skipped by providing ignoreTypeCheck argument with value true, which is necessary to merge a bundle containining an inline document's unique transitive dependencies, as inline documents typically are of different type (<script type="module"> within HTML document contains JavaScript document).

    function mergeMatchingBundles

    mergeMatchingBundles: (
    bundles: Bundle[],
    predicate: (bundle: Bundle) => boolean
    ) => Bundle[];
    • Return a new bundle array where bundles within it matching the predicate are merged together. Note that merge operations are segregated by type so that no attempt to merge bundles of different types will occur.

    function mergeSingleEntrypointSubBundles

    mergeSingleEntrypointSubBundles: (bundles: Bundle[]) => void;
    • Instances of <script type="module"> generate synthetic entrypoints in the depsIndex and are treated as entrypoints during the initial phase of generateBundles. Any bundle which provides dependencies to a single synthetic entrypoint of this type (aka a single entrypoint sub-bundle) are merged back into the bundle for the HTML containing the script tag.

      For example, the following bundles: [a]->[a], [a>1]->[x], [a>1,a>2]->[y], [a>2]->[z]

      Would be merged into the following set of bundles: [a]->[a,x,z], [a>1,a>2]->[y]

      a>1 and a>2 represent script tag entrypoints. Only x and z are bundled with a because they each serve only a single script tag entrypoint. y has to be in a separate bundle so that it is not inlined into bundle a in both script tags.

    Classes

    class AssignedBundle

    class AssignedBundle {}
    • Represents a bundle assigned to an output URL.

    property bundle

    bundle: Bundle;

      property url

      url: ResolvedUrl;

        class Bundle

        class Bundle {}
        • A bundle is a grouping of files which serve the need of one or more entrypoint files.

        constructor

        constructor(
        type: BundleType,
        entrypoints?: Set<ResolvedUrl>,
        files?: Set<ResolvedUrl>
        );

          property bundledExports

          bundledExports: Map<ResolvedUrl, Map<string, string>>;

            property entrypoints

            entrypoints: Set<ResolvedUrl>;

              property extname

              readonly extname: string;

                property files

                files: Set<ResolvedUrl>;

                  property inlinedHtmlImports

                  inlinedHtmlImports: Set<ResolvedUrl>;

                    property inlinedScripts

                    inlinedScripts: Set<ResolvedUrl>;

                      property inlinedStyles

                      inlinedStyles: Set<ResolvedUrl>;

                        property missingImports

                        missingImports: Set<ResolvedUrl>;

                          property stripImports

                          stripImports: Set<ResolvedUrl>;

                            property type

                            type: BundleType;

                              class BundleManifest

                              class BundleManifest {}
                              • A bundle manifest is a mapping of URLs to bundles.

                              constructor

                              constructor(bundles: Bundle[], urlMapper: BundleUrlMapper);
                              • Given a collection of bundles and a BundleUrlMapper to generate URLs for them, the constructor populates the bundles and files index properties.

                              property bundles

                              bundles: Map<ResolvedUrl, Bundle>;

                                method fork

                                fork: () => BundleManifest;

                                  method getBundleForFile

                                  getBundleForFile: (url: ResolvedUrl) => AssignedBundle | undefined;

                                    method toJson

                                    toJson: (urlResolver: UrlResolver) => BundleManifestJson;

                                      class Bundler

                                      class Bundler {}

                                        constructor

                                        constructor(options?: Options);

                                          property analyzer

                                          analyzer: Analyzer;

                                            property enableCssInlining

                                            enableCssInlining: boolean;

                                              property enableScriptInlining

                                              enableScriptInlining: boolean;

                                                property excludes

                                                excludes: ResolvedUrl[];

                                                  property rewriteUrlsInTemplates

                                                  rewriteUrlsInTemplates: boolean;

                                                    property sourcemaps

                                                    sourcemaps: boolean;

                                                      property strategy

                                                      strategy: BundleStrategy;

                                                        property stripComments

                                                        stripComments: boolean;

                                                          property treeshake

                                                          treeshake: boolean;

                                                            property urlMapper

                                                            urlMapper: BundleUrlMapper;

                                                              method analyzeContents

                                                              analyzeContents: (
                                                              url: ResolvedUrl,
                                                              contents: string,
                                                              permanent?: boolean
                                                              ) => Promise<Document>;
                                                              • Analyze an HTML URL using the given contents in place of what would otherwise have been loaded.

                                                              method bundle

                                                              bundle: (manifest: BundleManifest) => Promise<BundleResult>;
                                                              • Given a manifest describing the bundles, produce a collection of bundled documents with HTML imports, external stylesheets and external scripts inlined according to the options for this Bundler.

                                                                Parameter manifest

                                                                The manifest that describes the bundles to be produced.

                                                              method generateManifest

                                                              generateManifest: (entrypoints: ResolvedUrl[]) => Promise<BundleManifest>;
                                                              • Generates a BundleManifest with all bundles defined, using entrypoints, strategy and mapper.

                                                                Parameter entrypoints

                                                                The list of entrypoints that will be analyzed for dependencies. The results of the analysis will be passed to the strategy.

                                                                Parameter strategy

                                                                The strategy used to construct the output bundles. See 'polymer-analyzer/src/bundle-manifest'.

                                                                Parameter mapper

                                                                A function that produces URLs for the generated bundles. See 'polymer-analyzer/src/bundle-manifest'.

                                                              Interfaces

                                                              interface BundleManifestJson

                                                              interface BundleManifestJson {}

                                                                index signature

                                                                [entrypoint: string]: PackageRelativeUrl[];

                                                                  interface BundleResult

                                                                  interface BundleResult {}

                                                                    property documents

                                                                    documents: DocumentCollection;

                                                                      property manifest

                                                                      manifest: BundleManifest;

                                                                        interface Options

                                                                        interface Options {}

                                                                          property analyzer

                                                                          analyzer?: Analyzer;

                                                                            property excludes

                                                                            excludes?: ResolvedUrl[];

                                                                              property inlineCss

                                                                              inlineCss?: boolean;

                                                                                property inlineScripts

                                                                                inlineScripts?: boolean;

                                                                                  property rewriteUrlsInTemplates

                                                                                  rewriteUrlsInTemplates?: boolean;

                                                                                    property sourcemaps

                                                                                    sourcemaps?: boolean;

                                                                                      property strategy

                                                                                      strategy?: BundleStrategy;

                                                                                        property stripComments

                                                                                        stripComments?: boolean;

                                                                                          property treeshake

                                                                                          treeshake?: boolean;

                                                                                            property urlMapper

                                                                                            urlMapper?: BundleUrlMapper;

                                                                                              Type Aliases

                                                                                              type BundleStrategy

                                                                                              type BundleStrategy = (bundles: Bundle[]) => Bundle[];
                                                                                              • A bundle strategy function is used to transform an array of bundles.

                                                                                              type BundleType

                                                                                              type BundleType = 'html-fragment' | 'es6-module';
                                                                                              • The output format of the bundle.

                                                                                              type BundleUrlMapper

                                                                                              type BundleUrlMapper = (bundles: Bundle[]) => Map<ResolvedUrl, Bundle>;
                                                                                              • A bundle URL mapper function produces a map of URLs to bundles.

                                                                                              type TransitiveDependenciesMap

                                                                                              type TransitiveDependenciesMap = Map<ResolvedUrl, Set<ResolvedUrl>>;
                                                                                              • A mapping of entrypoints to their full set of transitive dependencies, such that a dependency graph a->c, c->d, d->e, b->d, b->f would be represented {a:[a,c,d,e], b:[b,d,e,f]}. Please note that there is an explicit identity dependency (a depends on a, b depends on b).

                                                                                              Namespaces

                                                                                              namespace command-line-args

                                                                                              module 'command-line-args' {}

                                                                                                function commandLineArgs

                                                                                                commandLineArgs: (args: commandLineArgs.ArgDescriptor[]) => any;

                                                                                                  interface ArgDescriptor

                                                                                                  interface ArgDescriptor {}

                                                                                                    property alias

                                                                                                    alias?: string;

                                                                                                      property defaultOption

                                                                                                      defaultOption?: boolean;

                                                                                                        property defaultValue

                                                                                                        defaultValue?: any;

                                                                                                          property description

                                                                                                          description?: string;

                                                                                                            property group

                                                                                                            group?: string;

                                                                                                              property multiple

                                                                                                              multiple?: boolean;

                                                                                                                property name

                                                                                                                name: string;

                                                                                                                  property type

                                                                                                                  type?: Object;

                                                                                                                    interface UsageOpts

                                                                                                                    interface UsageOpts {}

                                                                                                                      property description

                                                                                                                      description?: string;

                                                                                                                        property groups

                                                                                                                        groups?: any;

                                                                                                                          property header

                                                                                                                          header?: string;

                                                                                                                            property title

                                                                                                                            title?: string;

                                                                                                                              namespace command-line-usage

                                                                                                                              module 'command-line-usage' {}

                                                                                                                                function commandLineUsage

                                                                                                                                commandLineUsage: (args: any) => string;

                                                                                                                                  namespace espree

                                                                                                                                  module 'espree' {}

                                                                                                                                    function tokenize

                                                                                                                                    tokenize: (text: string, opts?: ParseOpts2) => Token[];

                                                                                                                                      interface ParseOpts2

                                                                                                                                      interface ParseOpts2 {}

                                                                                                                                        property ecmaVersion

                                                                                                                                        ecmaVersion?: number;

                                                                                                                                          property loc

                                                                                                                                          loc?: boolean;

                                                                                                                                            property sourceType

                                                                                                                                            sourceType?: 'script' | 'module';

                                                                                                                                              interface Token

                                                                                                                                              interface Token {}

                                                                                                                                                property end

                                                                                                                                                end: number;

                                                                                                                                                  property loc

                                                                                                                                                  loc: {
                                                                                                                                                  start: {
                                                                                                                                                  line: number;
                                                                                                                                                  column: number;
                                                                                                                                                  };
                                                                                                                                                  end: {
                                                                                                                                                  line: number;
                                                                                                                                                  column: number;
                                                                                                                                                  };
                                                                                                                                                  };

                                                                                                                                                    property start

                                                                                                                                                    start: number;

                                                                                                                                                      property type

                                                                                                                                                      type: string;

                                                                                                                                                        property value

                                                                                                                                                        value: string;

                                                                                                                                                          namespace mkdirp

                                                                                                                                                          module 'mkdirp' {}

                                                                                                                                                            function mkdirp

                                                                                                                                                            mkdirp: typeof mkdirp;

                                                                                                                                                              function sync

                                                                                                                                                              sync: (dir: string, opts?: {}) => void;

                                                                                                                                                                Package Files (6)

                                                                                                                                                                Dependencies (17)

                                                                                                                                                                Dev Dependencies (9)

                                                                                                                                                                Peer Dependencies (0)

                                                                                                                                                                No peer dependencies.

                                                                                                                                                                Badge

                                                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/polymer-bundler.

                                                                                                                                                                • Markdown
                                                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/polymer-bundler)
                                                                                                                                                                • HTML
                                                                                                                                                                  <a href="https://www.jsdocs.io/package/polymer-bundler"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>