@winner-fed/bundler-webpack
Version:
@winner-fed/bundler-webpack
248 lines (247 loc) • 5.61 kB
TypeScript
import type { Options as SwcConfig } from '@swc/core';
import type { HttpsServerOptions, ProxyOptions } from '@winner-fed/bundler-utils';
import type { TransformOptions as EsbuildOptions } from '@winner-fed/bundler-utils/compiled/esbuild';
import type CompressionPlugin from 'compression-webpack-plugin';
import type { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import webpack, { Configuration } from '../compiled/webpack';
import Config from '../compiled/webpack-5-chain';
type GenericConfig = {
[key: string]: any;
};
export declare enum Env {
development = "development",
production = "production"
}
export declare enum Transpiler {
babel = "babel",
swc = "swc",
esbuild = "esbuild",
none = "none"
}
export declare enum JSMinifier {
terser = "terser",
swc = "swc",
esbuild = "esbuild",
uglifyJs = "uglifyJs",
none = "none"
}
export declare enum CSSMinifier {
esbuild = "esbuild",
cssnano = "cssnano",
parcelCSS = "parcelCSS",
none = "none"
}
export interface ICopy {
from: string;
to: string;
}
type WebpackConfig = Required<Configuration>;
type IBabelPlugin = Function | string | [string, GenericConfig] | [string, GenericConfig, string];
export interface DeadCodeParams {
patterns?: string[];
exclude?: string[];
failOnHint?: boolean;
detectUnusedFiles?: boolean;
detectUnusedExport?: boolean;
context?: string;
}
export interface IConfig {
/**
* 模块别名配置
*/
alias?: Record<string, string>;
/**
* 是否开启自动 CSS Modules
*/
autoCSSModules?: boolean;
/**
* 基础路径
*/
base?: string;
/**
* webpack 配置链式调用
*/
chainWebpack?: {
(memo: Config, args: {
env: keyof typeof Env;
webpack: typeof webpack;
}): void;
};
/**
* 静态资源拷贝配置
*/
copy?: ICopy[] | string[];
/**
* css-loader 配置
*/
cssLoader?: GenericConfig;
/**
* CSS Loader Modules 配置
*/
cssLoaderModules?: GenericConfig;
/**
* CSS 压缩工具选择
*/
cssMinifier?: `${CSSMinifier}`;
/**
* CSS 压缩工具选项
*/
cssMinifierOptions?: GenericConfig;
/**
* 全局定义变量
*/
define?: GenericConfig;
/**
* 依赖转译工具选择
*/
depTranspiler?: `${Transpiler}`;
/**
* 开发工具配置
*/
devtool?: Config.DevTool;
/**
* 死代码检测配置
*/
deadCode?: DeadCodeParams;
/**
* HTTPS 服务器配置
*/
https?: HttpsServerOptions;
/**
* webpack externals 配置
*/
externals?: WebpackConfig['externals'];
/**
* ESM 配置
*/
esm?: GenericConfig;
/**
* 额外的 Babel 插件
*/
extraBabelPlugins?: IBabelPlugin[];
/**
* 额外的 Babel 预设
*/
extraBabelPresets?: IBabelPlugin[];
/**
* 额外的 Babel 包含路径
*/
extraBabelIncludes?: Array<string | RegExp>;
/**
* 额外的 Babel 排除路径
*/
extraBabelExcludes?: Array<string | RegExp>;
/**
* 额外的 PostCSS 插件
*/
extraPostCSSPlugins?: any[];
/**
* 是否开启哈希文件名
*/
hash?: boolean;
/**
* 是否忽略 Moment.js 的本地化文件
*/
ignoreMomentLocale?: boolean;
/**
* JS 压缩工具选择
*/
jsMinifier?: `${JSMinifier}`;
/**
* JS 压缩工具选项
*/
jsMinifierOptions?: GenericConfig;
/**
* Less Loader 配置
*/
lessLoader?: GenericConfig;
/**
* 普通 CSS Loader Modules 配置
*/
normalCSSLoaderModules?: GenericConfig;
/**
* 输出路径
*/
outputPath?: string;
/**
* PostCSS Loader 配置
*/
postcssLoader?: GenericConfig;
/**
* 代理配置
*/
proxy?: {
[key: string]: ProxyOptions;
} | ProxyOptions[];
/**
* 公共路径
*/
publicPath?: string;
/**
* PurgeCSS 配置
*/
purgeCSS?: GenericConfig;
/**
* Sass Loader 配置
*/
sassLoader?: GenericConfig;
/**
* 源代码转译工具选择
*/
srcTranspiler?: `${Transpiler}`;
/**
* 源代码转译工具选项
*/
srcTranspilerOptions?: ISrcTranspilerOpts;
/**
* Style Loader 配置,或禁用
*/
styleLoader?: GenericConfig | false;
/**
* SVGO 配置,或禁用
*/
svgo?: GenericConfig | false;
/**
* 目标环境配置
*/
targets?: GenericConfig;
/**
* 是否写入磁盘
*/
writeToDisk?: boolean;
/**
* Babel Loader 自定义配置
*/
babelLoaderCustomize?: string;
/**
* 分析工具配置
*/
analyze?: BundleAnalyzerPlugin.Options;
/**
* 压缩插件配置
*/
compression?: CompressionPlugin.InternalPluginOptions<any>;
/**
* 是否使用 esbuild 压缩 IIFE
*/
esbuildMinifyIIFE?: boolean;
/**
* 是否检查依赖中的 CSS Modules
*/
checkDepCssModules?: boolean;
[key: string]: any;
}
export interface ISrcTranspilerOpts {
swc?: Partial<SwcConfig>;
esbuild?: Partial<EsbuildOptions>;
}
export interface ISwcPluginOpts {
enableAutoCssModulesPlugin?: boolean;
}
export interface SwcOptions extends SwcConfig, ISwcPluginOpts {
sync?: boolean;
parseMap?: boolean;
excludeFiles?: Array<string | RegExp>;
mergeConfigs?: Partial<SwcConfig>;
}
export {};