@sanpjs/core
Version:
@sanpjs/core
190 lines (180 loc) • 5.01 kB
TypeScript
import {RuleSetRule, RuleSetUseItem, Configuration} from 'webpack';
import Server from 'webpack-dev-server';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import Resolver from '../src/Resolver';
import Sanp from '../src/Sanp';
import TerserPlugin from 'terser-webpack-plugin';
export enum Type {
spa = 'spa',
mpa = 'mpa',
'spa-ssr' = 'spa-ssr',
'mpa-ssr' = 'mpa-ssr',
component = 'component'
}
export type IType = keyof typeof Type;
export interface SObject {
[key: string]: string;
}
export interface Attr {
[attributeName: string]: string | boolean | null | undefined;
}
export interface HtmlTag {
attributes?: Attr;
tag?: HtmlWebpackPlugin.HtmlTagObject[];
}
export interface HtmlConfig {
name: string;
filepath: string;
filename?: string;
layout?: string;
title?: string;
html?: {
attributes?: Attr;
};
head?: HtmlTag;
body?: HtmlTag;
}
export enum Option {
off = 'off',
info = 'info',
warn = 'warn',
error = 'error'
}
export type IOption = keyof typeof Option;
export interface Opt {
[key: string]: 'off' | 'info';
}
export interface IRule {
[key: string]: (context: Context) => RuleSetRule;
}
export interface ILoader {
(name: string, context: Context): RuleSetUseItem;
}
export interface ILoaders {
(name: string[], context: Context): RuleSetUseItem[];
}
export interface Internals {
rules: IRule;
loader: ILoader;
loaders: ILoaders;
replaceOption: (
test: string | RegExp,
loader: string,
options: string | {[index: string]: any},
config: Configuration
) => void;
replaceRule: (test: string | RegExp, use: RuleSetUseItem, config: Configuration) => void;
}
export type IPlugin = Function | Function[] | Array<{apply: Function}>;
export interface IConfig {
root: string;
pagesDir: string;
sanpDir: string;
attachedElement: string;
type: string;
mode: string;
plugins?: IPlugin;
pages?: string | HtmlConfig | HtmlConfig[];
progress?: boolean;
watch?: boolean;
build?: {
copy?: (string | SObject)[];
outDir?: string;
analyze?: boolean | SObject;
clean?: boolean;
esModule?: boolean;
sourceMap?: boolean | string;
publicPath?: string;
assetDir?: string;
hash?: boolean;
largeAssetSize?: number;
cache?: boolean | {[key: string]: any};
parallel?: boolean;
esbuild?: boolean;
inspect?: {
initialRes?: {
count?: Opt | (IOption | number)[];
totalSize?: Opt | (IOption | number)[];
sizeDeviation?: Opt | (IOption | number)[];
disallowImports?: Opt | (IOption | string[])[];
};
dupPkg?:
| IOption
| (
| IOption
| {
includes?: (string | RegExp)[];
excludes?: (string | RegExp)[];
}
)[];
esCheck?:
| IOption
| (
| IOption
| {
includes?: (string | RegExp)[];
excludes?: (string | RegExp)[];
parseOptions?: SObject;
}
)[];
};
script?: {
babel?: boolean | {[key: string]: any};
polyfills?: string[] | string | boolean;
finalize?: {
(internalBabelConfig: any, context: Context): any;
};
};
style: {
extract?: boolean;
modules?: boolean | {[key: string]: any};
};
optimization: {
splitChunks: object;
terser: TerserPlugin.TerserOptions;
cssnano: object;
htmlMinify?: 'auto' | boolean | HtmlWebpackPlugin.MinifyOptions;
};
finalize?: {
(webpackConfig: Configuration, internals: Internals, context: Context): Configuration;
};
};
server?: {
finalize?: {
(devServerConfig: any, context: Context): Server.Configuration;
};
[key: string]: any;
};
ssr?: any;
[key: string]: any;
}
export interface Context {
config: Config;
resolver: Resolver;
plugins: IPlugin;
sanp: Sanp;
cwd: string;
rawConfig: object;
sanpDir: string;
configFile: string;
pkg: object;
pages: any[];
root: string;
build: IConfig.build;
server: IConfig.server;
ssr: IConfig.ssr;
mode: 'development' | 'production';
dev: boolean;
prod: boolean;
watch: IConfig.watch;
progress: IConfig.progress;
type: IConfig.type;
isSsr: boolean;
toJSON: Function;
inspect: Function;
[key: string]: any;
}
export interface Opts {
Bundler?: any;
Builder?: any;
}