UNPKG

@ices/locale-webpack-plugin

Version:
107 lines (106 loc) 2.98 kB
import * as webpack from 'webpack'; import { RuleSetCondition } from 'webpack'; import ExtractPlugin, { ExtractPluginOptions } from './lib/ExtractPlugin'; export interface LoaderType extends webpack.loader.Loader { test?: RegExp; filepath: string; libName?: string; resourceQuery?: RuleSetCondition; extensions?: string[]; [key: string]: any; } declare type ModuleGeneratorOptions = { hot: boolean; module: string; esModule: boolean; resourcePath: string; rootContext: string; }; interface ComponentLoader { getModuleCode(opts: ModuleGeneratorOptions): string; getModuleExports(): string; } export declare type LoaderOptions = { mode?: string; esModule: boolean; extract: boolean; extensions: string[]; generator: ComponentLoader['getModuleCode']; extractor: ExtractPlugin | null; resolveAlias: { [p: string]: string; } | null; }; declare type PluginOptions = { /** * 语言定义文件的名称匹配正则表达式。 * 用于对匹配到的文件进行模块化处理。 * 默认匹配yml后缀格式文件。 */ test?: RuleSetCondition; /** * 查询条件排除。 */ exclude?: RuleSetCondition; /** * 查询条件包含。 */ include?: RuleSetCondition; /** * 是否使用es模块导出代码。 * 默认为 true。 */ esModule?: boolean; /** * 需要使用的模块组件的类型。 * 目前可选值为 react ,暂不支持 vue 。 * 默认值为 react。 */ componentType?: ComponentType; /** * 是否将语言定义文件抽取成单独的文件发布。 * 默认根据运行环境自动设值。 */ extract?: boolean; /** * 抽取语言定义插件的配置项。 */ extractOptions?: ExtractPluginOptions; }; /** * 使用的组件类型。 * 暂未提供vue组件。 */ declare enum ComponentType { react = "react", vue = "vue" } /** * 用于加载解析语言定义文件至组件模块的webpack插件。 */ export default class LocaleWebpackPlugin implements webpack.Plugin { private readonly options; private readonly fileLoaders; private readonly extensions; private readonly moduleGenerator; private extractPlugin; private resolveAlias; private mode; constructor(options?: PluginOptions); getLibModuleDetails(componentType?: ComponentType): { name: string; context: string; packageModule: { [p: string]: string; }; loaderModule: any; }; getModuleGenerator({ loaderModule, name }: { loaderModule: ComponentLoader; name: string; }): (opts: ModuleGeneratorOptions) => string; getSupportedExtensions(): string[]; getLoaderRule({ filepath, test, resourceQuery }: LoaderType, extractLocales?: boolean): webpack.RuleSetRule; apply(compiler: webpack.Compiler): void; } export {};