UNPKG

3.93 kBTypeScriptView Raw
1// https://umijs.org/config/
2import { ExternalsElement, Condition } from 'webpack';
3import * as IWebpackChainConfig from 'webpack-chain';
4import { ReactNode } from 'react';
5import { IChangeWebpackConfigFunc } from './index';
6
7export type IPlugin<T = any> = string | [string, T];
8
9export interface IRoute {
10 path?: string;
11 component?: ReactNode;
12 routes?: IRoute[];
13 Routes?: string[];
14 redirect?: string;
15 [key: string]: any;
16}
17
18export interface IExportStaticOpts {
19 htmlSuffix?: boolean;
20 dynamicRoot?: boolean;
21}
22
23// sorted by alphabet
24export interface IAFWebpackConfig {
25 alias?: object; // https://webpack.js.org/configuration/resolve/#resolve-alias
26 autoprefixer?: object; // https://github.com/ai/browserslist
27 babel?: object;
28 browserslist?: string[]; // https://github.com/ai/browserslist
29 chainConfig?: any; // https://github.com/mozilla-neutrino/webpack-chain
30 copy?: any[]; // https://github.com/webpack-contrib/copy-webpack-plugin
31 cssLoaderOptions?: any; // https://github.com/webpack-contrib/css-loader
32 cssModulesExcludes?: string[];
33 cssModulesWithAffix?: boolean;
34 cssnano?: object;
35 cssPublicPath?: string;
36 generateCssModulesTypings?: boolean;
37 define?: object;
38 devServer?: object; // https://webpack.js.org/configuration/dev-server/#devserver
39 devtool?: string | false; // https://webpack.js.org/configuration/devtool/
40 disableCSSModules?: boolean;
41 disableCSSSourceMap?: boolean;
42 disableDynamicImport?: boolean;
43 disableGlobalVariables?: boolean;
44 cssLoaderVersion?: 1 | 2;
45 entry?: any;
46 env?: object;
47 es5ImcompatibleVersions?: boolean;
48 externals?: ExternalsElement; // https://webpack.js.org/configuration/externals/
49 extraBabelIncludes?: Condition[]; // https://webpack.js.org/configuration/module/#condition
50 extraBabelPlugins?: any[];
51 extraBabelPresets?: any[];
52 extraPostCSSPlugins?: any[];
53 hash?: boolean;
54 ignoreMomentLocale?: boolean;
55 lessLoaderOptions?: any; // https://github.com/webpack-contrib/less-loader
56 manifest?: any; // https://www.npmjs.com/package/webpack-manifest-plugin
57 minimizer?: 'uglifyjs' | 'terserjs';
58 outputPath?: string;
59 proxy?: object | [object, Function]; // https://webpack.js.org/configuration/dev-server/#devserver-proxy
60 publicPath?: string;
61 sass?: object; // https://github.com/sass/node-sass#options
62 terserJSOptions?: object;
63 theme?: string | object;
64 tsConfigFile?: string;
65 typescript?: object;
66 uglifyJSOptions?: object;
67 urlLoaderExcludes?: Condition[];
68}
69
70type WhitelistOption = string | RegExp;
71export type IExportSSROpts =
72 | {
73 /** not external library, https://github.com/liady/webpack-node-externals#optionswhitelist- */
74 externalWhitelist?: WhitelistOption[];
75 /** webpack-node-externals config */
76 nodeExternalsOpts?: object;
77 /** client chunkMaps manifest, default: ssr-client-mainifest.json */
78 manifestFileName?: string;
79 /** disable ssr external */
80 disableExternal?: boolean;
81 /** disable ssr external, build all modules in `umi.server.js` */
82 disableExternalWhiteList?: string[] | object;
83 }
84 | boolean;
85
86export interface IMockOpts {
87 exclude?: string[] | string;
88}
89
90interface IConfig extends IAFWebpackConfig {
91 // basic config
92 // sorted by alphabet
93 block?: object;
94 chainWebpack?: IChangeWebpackConfigFunc<IWebpackChainConfig, IAFWebpackConfig>; // https://github.com/mozilla-neutrino/webpack-chain
95 context?: object;
96 disableRedirectHoist?: boolean;
97 exportStatic?: boolean | IExportStaticOpts;
98 outputPath?: string;
99 plugins?: IPlugin[];
100 routes?: IRoute[] | null;
101 runtimePublicPath?: boolean | string;
102 singular?: boolean;
103 mock?: IMockOpts;
104 treeShaking?: boolean;
105 dva?: any;
106 locale?: any;
107
108 // implemented in plugins
109 base?: string;
110 history?: 'browser' | 'hash' | 'memory';
111 mountElementId?: string;
112 targets?: {
113 [key: string]: number;
114 };
115 ssr?: IExportSSROpts;
116}
117
118export default IConfig;