st-bundle
Version:
CLI for watching and bundling SpringType projects.
95 lines (94 loc) • 2.63 kB
TypeScript
/// <reference types="node" />
import { Context } from '../core/Context';
import { Package } from '../core/Package';
import { IWriterResponse } from '../core/writer';
import { Concat } from '../utils/utils';
/**
* Bundle types with priorities
* The numbers should not be changed
*/
export declare enum BundleType {
CSS = 1,
DEV = 2,
VENDOR_JS = 3,
PROJECT_JS = 4,
PROJECT_ENTRY = 5,
SERVER_ENTRY = 6,
SPLIT_JS = 7
}
/**
* Mapped bundle names
* Those could be changed it's mainly used for development
*/
export declare const BundleNames: {
[BundleType.CSS]: string;
[BundleType.DEV]: string;
[BundleType.PROJECT_JS]: string;
[BundleType.PROJECT_ENTRY]: string;
[BundleType.VENDOR_JS]: string;
};
export interface IBundleProps {
ctx: Context;
name: string;
priority?: number;
webIndexed?: boolean;
type: BundleType;
skipHash?: boolean;
}
export interface IBundleWriteResponse {
bundle: Bundle;
stat: IWriterResponse;
}
export declare type BundleCollection = {
[key: string]: Bundle;
};
/**
* If a bundle doesn't exist in the collection it creates a new one
* @param collection
* @param ctx
* @param type
*/
export declare function getBundleByType(collection: BundleCollection, ctx: Context, type: BundleType, webIndexed?: boolean): Bundle;
/**
* Creates a bundle set for convenience of creationing new bundes by type
* @param ctx
*/
export declare function createBundleSet(ctx: Context): {
collection: BundleCollection;
getBundle: (type: BundleType) => Bundle;
};
export declare class Bundle {
props: IBundleProps;
packages: Array<Package>;
isolated?: boolean;
contents: Concat;
noHash?: boolean;
name: string;
useCustomGenerator: boolean;
constructor(props: IBundleProps);
flush(): void;
prependContent(contents: string, sm?: string): void;
setCustomName(name: string): void;
addContent(contents: string | Buffer, sm?: any): void;
addConcat(concat: Concat): void;
override(contents: string, sm: any): void;
addPackage(pkg: Package): void;
isJavascriptType(): boolean;
needsSourceMaps(): boolean;
private generateSourceMapFileName;
getFileName(): string;
/**
* Write bundle with sourcemaps if needed
* @param withSourceMaps
*/
private write;
/**
* Generates a function that writes contents with sourcemaps
*/
generate(): {
write: () => Promise<IBundleWriteResponse>;
contents: string;
sourceMap: string;
};
}
export declare function createBundle(props: IBundleProps): Bundle;