@regru/webpack-babel-multi-target-plugin
Version:
A Webpack plugin that works with Babel to allow deployment of ES2015 builds targeted to modern browsers, with an ES5 fallback for legacy browsers.
54 lines (53 loc) • 2.45 kB
TypeScript
import { BabelLoaderTransformOptions, BabelPresetOptions } from 'babel-loader';
import * as webpack from 'webpack';
import Chunk = webpack.compilation.Chunk;
import ChunkGroup = webpack.compilation.ChunkGroup;
import Entrypoint = webpack.compilation.Entrypoint;
import Module = webpack.compilation.Module;
import { BabelLoaderCacheDirectoryOption } from './babel.multi.target.options';
import { BabelTargetOptions } from './babel.target.options';
import { BrowserProfileName } from './browser.profile.name';
export declare type BabelTargetSource = Module | Chunk | ChunkGroup;
/**
* Represents a targeted transpilation output.
*
* Includes properties from {@link BabelTargetOptions}, but all properties are required.
*/
export declare type BabelTargetInfo = {
[TOption in keyof BabelTargetOptions]: BabelTargetOptions[TOption];
} & {
readonly profileName: BrowserProfileName;
readonly options: BabelLoaderTransformOptions;
};
export declare class BabelTarget implements BabelTargetInfo {
readonly profileName: BrowserProfileName;
readonly key: string;
readonly options: BabelLoaderTransformOptions;
readonly tagAssetsWithKey: boolean;
readonly browsers: string[];
readonly esModule: boolean;
readonly noModule: boolean;
readonly additionalModules: string[];
constructor(info: BabelTargetInfo);
getTargetedAssetName(name: string): string;
getTargetedRequest(request: string): string;
static isTaggedRequest(request: string): boolean;
static getTargetFromTag(request: string, targets: BabelTarget[]): BabelTarget;
static getTargetFromModule(module: Module): BabelTarget;
static getTargetFromEntrypoint(entrypoint: Entrypoint): BabelTarget;
static getTargetFromGroup(group: ChunkGroup): BabelTarget;
static getTargetFromChunk(chunk: Chunk): BabelTarget;
static findTarget(source: BabelTargetSource): BabelTarget;
}
export declare class BabelTargetFactory {
private presetOptions;
private plugins;
constructor(presetOptions: BabelPresetOptions, plugins: string[]);
createBabelTarget(profileName: BrowserProfileName, options: BabelTargetOptions, loaderOptions: {
cacheDirectory?: BabelLoaderCacheDirectoryOption;
}): BabelTarget;
createTransformOptions(key: string, browsers: string[], loaderOptions: {
cacheDirectory?: BabelLoaderCacheDirectoryOption;
}): BabelLoaderTransformOptions;
private getCacheDirectory;
}