@umijs/preset-umi 4.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/assets/umi.png +0 -0
- package/compiled/body-parser/LICENSE +23 -0
- package/compiled/body-parser/connect/index.d.ts +93 -0
- package/compiled/body-parser/index.d.ts +107 -0
- package/compiled/body-parser/index.js +129 -0
- package/compiled/body-parser/package.json +1 -0
- package/compiled/multer/LICENSE +17 -0
- package/compiled/multer/body-parser/index.d.ts +104 -0
- package/compiled/multer/connect/index.d.ts +93 -0
- package/compiled/multer/express/index.d.ts +133 -0
- package/compiled/multer/express-serve-static-core/index.d.ts +1252 -0
- package/compiled/multer/index.d.ts +321 -0
- package/compiled/multer/index.js +41 -0
- package/compiled/multer/mime/index.d.ts +35 -0
- package/compiled/multer/package.json +1 -0
- package/compiled/multer/qs/index.d.ts +62 -0
- package/compiled/multer/range-parser/index.d.ts +35 -0
- package/compiled/multer/serve-static/index.d.ts +108 -0
- package/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.js +120 -0
- package/dist/commands/config/config.d.ts +3 -0
- package/dist/commands/config/config.js +61 -0
- package/dist/commands/config/list.d.ts +2 -0
- package/dist/commands/config/list.js +34 -0
- package/dist/commands/config/remove.d.ts +1 -0
- package/dist/commands/config/remove.js +21 -0
- package/dist/commands/config/set.d.ts +1 -0
- package/dist/commands/config/set.js +21 -0
- package/dist/commands/dev/createRouteMiddleware.d.ts +5 -0
- package/dist/commands/dev/createRouteMiddleware.js +35 -0
- package/dist/commands/dev/dev.d.ts +3 -0
- package/dist/commands/dev/dev.js +269 -0
- package/dist/commands/dev/faviconMiddleware.d.ts +2 -0
- package/dist/commands/dev/faviconMiddleware.js +13 -0
- package/dist/commands/dev/getBabelOpts.d.ts +20 -0
- package/dist/commands/dev/getBabelOpts.js +57 -0
- package/dist/commands/dev/getMarkupArgs.d.ts +13 -0
- package/dist/commands/dev/getMarkupArgs.js +73 -0
- package/dist/commands/dev/watch.d.ts +19 -0
- package/dist/commands/dev/watch.js +55 -0
- package/dist/commands/generate/page.d.ts +3 -0
- package/dist/commands/generate/page.js +44 -0
- package/dist/commands/generate/prettier.d.ts +3 -0
- package/dist/commands/generate/prettier.js +31 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.js +61 -0
- package/dist/commands/plugin.d.ts +3 -0
- package/dist/commands/plugin.js +38 -0
- package/dist/commands/setup.d.ts +3 -0
- package/dist/commands/setup.js +20 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.js +16 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +8 -0
- package/dist/features/__sample.d.ts +3 -0
- package/dist/features/__sample.js +5 -0
- package/dist/features/appData/appData.d.ts +3 -0
- package/dist/features/appData/appData.js +30 -0
- package/dist/features/check/check.d.ts +3 -0
- package/dist/features/check/check.js +34 -0
- package/dist/features/configPlugins/configPlugins.d.ts +3 -0
- package/dist/features/configPlugins/configPlugins.js +61 -0
- package/dist/features/configPlugins/schema.d.ts +2 -0
- package/dist/features/configPlugins/schema.js +16 -0
- package/dist/features/esmi/esmi.d.ts +3 -0
- package/dist/features/esmi/esmi.js +44 -0
- package/dist/features/favicon/favicon.d.ts +3 -0
- package/dist/features/favicon/favicon.js +58 -0
- package/dist/features/lowImport/babelPlugin.d.ts +17 -0
- package/dist/features/lowImport/babelPlugin.js +68 -0
- package/dist/features/lowImport/lowImport.d.ts +9 -0
- package/dist/features/lowImport/lowImport.js +108 -0
- package/dist/features/mock/constants.d.ts +3 -0
- package/dist/features/mock/constants.js +14 -0
- package/dist/features/mock/createMockMiddleware.d.ts +7 -0
- package/dist/features/mock/createMockMiddleware.js +82 -0
- package/dist/features/mock/getMockData.d.ts +9 -0
- package/dist/features/mock/getMockData.js +61 -0
- package/dist/features/mock/mock.d.ts +2 -0
- package/dist/features/mock/mock.js +50 -0
- package/dist/features/polyfill/polyfill.d.ts +3 -0
- package/dist/features/polyfill/polyfill.js +14 -0
- package/dist/features/tmpFiles/importsToStr.d.ts +4 -0
- package/dist/features/tmpFiles/importsToStr.js +16 -0
- package/dist/features/tmpFiles/routes.d.ts +8 -0
- package/dist/features/tmpFiles/routes.js +74 -0
- package/dist/features/tmpFiles/tmpFiles.d.ts +3 -0
- package/dist/features/tmpFiles/tmpFiles.js +124 -0
- package/dist/features/transform/babelPlugin.d.ts +11 -0
- package/dist/features/transform/babelPlugin.js +118 -0
- package/dist/features/transform/transform.d.ts +3 -0
- package/dist/features/transform/transform.js +29 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -0
- package/dist/libs/moduleGraph.d.ts +2 -0
- package/dist/libs/moduleGraph.js +6 -0
- package/dist/libs/scan.d.ts +28 -0
- package/dist/libs/scan.js +110 -0
- package/dist/registerMethods.d.ts +3 -0
- package/dist/registerMethods.js +89 -0
- package/dist/types.d.ts +147 -0
- package/dist/types.js +2 -0
- package/dist/utils/clearTmp.d.ts +1 -0
- package/dist/utils/clearTmp.js +17 -0
- package/dist/utils/isTypeScriptFile.d.ts +1 -0
- package/dist/utils/isTypeScriptFile.js +7 -0
- package/package.json +62 -0
- package/templates/generate/page/index.less.tpl +4 -0
- package/templates/generate/page/index.tsx.tpl +10 -0
- package/templates/plugin.tpl +18 -0
- package/templates/route.tpl +7 -0
- package/templates/umi.tpl +22 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Type definitions for mime 1.3
|
|
2
|
+
// Project: https://github.com/broofa/node-mime
|
|
3
|
+
// Definitions by: Jeff Goddard <https://github.com/jedigo>
|
|
4
|
+
// Daniel Hritzkiv <https://github.com/dhritzkiv>
|
|
5
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
6
|
+
|
|
7
|
+
// Originally imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts
|
|
8
|
+
|
|
9
|
+
export as namespace mime;
|
|
10
|
+
|
|
11
|
+
export interface TypeMap { [key: string]: string[]; }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Look up a mime type based on extension.
|
|
15
|
+
*
|
|
16
|
+
* If not found, uses the fallback argument if provided, and otherwise
|
|
17
|
+
* uses `default_type`.
|
|
18
|
+
*/
|
|
19
|
+
export function lookup(path: string, fallback?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Return a file extensions associated with a mime type.
|
|
22
|
+
*/
|
|
23
|
+
export function extension(mime: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Load an Apache2-style ".types" file.
|
|
26
|
+
*/
|
|
27
|
+
export function load(filepath: string): void;
|
|
28
|
+
export function define(mimes: TypeMap): void;
|
|
29
|
+
|
|
30
|
+
export interface Charsets {
|
|
31
|
+
lookup(mime: string, fallback: string): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const charsets: Charsets;
|
|
35
|
+
export const default_type: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"multer","license":"MIT"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Type definitions for qs 6.9
|
|
2
|
+
// Project: https://github.com/ljharb/qs
|
|
3
|
+
// Definitions by: Roman Korneev <https://github.com/RWander>
|
|
4
|
+
// Leon Yu <https://github.com/leonyu>
|
|
5
|
+
// Belinda Teh <https://github.com/tehbelinda>
|
|
6
|
+
// Melvin Lee <https://github.com/zyml>
|
|
7
|
+
// Arturs Vonda <https://github.com/artursvonda>
|
|
8
|
+
// Carlos Bonetti <https://github.com/CarlosBonetti>
|
|
9
|
+
// Dan Smith <https://github.com/dpsmith3>
|
|
10
|
+
// Hunter Perrin <https://github.com/hperrin>
|
|
11
|
+
// Jordan Harband <https://github.com/ljharb>
|
|
12
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
13
|
+
export = QueryString;
|
|
14
|
+
export as namespace qs;
|
|
15
|
+
|
|
16
|
+
declare namespace QueryString {
|
|
17
|
+
type defaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
|
|
18
|
+
type defaultDecoder = (str: string, decoder?: any, charset?: string) => string;
|
|
19
|
+
|
|
20
|
+
interface IStringifyOptions {
|
|
21
|
+
delimiter?: string | undefined;
|
|
22
|
+
strictNullHandling?: boolean | undefined;
|
|
23
|
+
skipNulls?: boolean | undefined;
|
|
24
|
+
encode?: boolean | undefined;
|
|
25
|
+
encoder?: ((str: any, defaultEncoder: defaultEncoder, charset: string, type: 'key' | 'value') => string) | undefined;
|
|
26
|
+
filter?: Array<string | number> | ((prefix: string, value: any) => any) | undefined;
|
|
27
|
+
arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma' | undefined;
|
|
28
|
+
indices?: boolean | undefined;
|
|
29
|
+
sort?: ((a: any, b: any) => number) | undefined;
|
|
30
|
+
serializeDate?: ((d: Date) => string) | undefined;
|
|
31
|
+
format?: 'RFC1738' | 'RFC3986' | undefined;
|
|
32
|
+
encodeValuesOnly?: boolean | undefined;
|
|
33
|
+
addQueryPrefix?: boolean | undefined;
|
|
34
|
+
allowDots?: boolean | undefined;
|
|
35
|
+
charset?: 'utf-8' | 'iso-8859-1' | undefined;
|
|
36
|
+
charsetSentinel?: boolean | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface IParseOptions {
|
|
40
|
+
comma?: boolean | undefined;
|
|
41
|
+
delimiter?: string | RegExp | undefined;
|
|
42
|
+
depth?: number | false | undefined;
|
|
43
|
+
decoder?: ((str: string, defaultDecoder: defaultDecoder, charset: string, type: 'key' | 'value') => any) | undefined;
|
|
44
|
+
arrayLimit?: number | undefined;
|
|
45
|
+
parseArrays?: boolean | undefined;
|
|
46
|
+
allowDots?: boolean | undefined;
|
|
47
|
+
plainObjects?: boolean | undefined;
|
|
48
|
+
allowPrototypes?: boolean | undefined;
|
|
49
|
+
parameterLimit?: number | undefined;
|
|
50
|
+
strictNullHandling?: boolean | undefined;
|
|
51
|
+
ignoreQueryPrefix?: boolean | undefined;
|
|
52
|
+
charset?: 'utf-8' | 'iso-8859-1' | undefined;
|
|
53
|
+
charsetSentinel?: boolean | undefined;
|
|
54
|
+
interpretNumericEntities?: boolean | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ParsedQs { [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[] }
|
|
58
|
+
|
|
59
|
+
function stringify(obj: any, options?: IStringifyOptions): string;
|
|
60
|
+
function parse(str: string, options?: IParseOptions & { decoder?: never | undefined }): ParsedQs;
|
|
61
|
+
function parse(str: string | Record<string, string>, options?: IParseOptions): { [key: string]: unknown };
|
|
62
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Type definitions for range-parser 1.2
|
|
2
|
+
// Project: https://github.com/jshttp/range-parser
|
|
3
|
+
// Definitions by: Tomek Łaziuk <https://github.com/tlaziuk>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* When ranges are returned, the array has a "type" property which is the type of
|
|
8
|
+
* range that is required (most commonly, "bytes"). Each array element is an object
|
|
9
|
+
* with a "start" and "end" property for the portion of the range.
|
|
10
|
+
*
|
|
11
|
+
* @returns `-1` when unsatisfiable and `-2` when syntactically invalid, ranges otherwise.
|
|
12
|
+
*/
|
|
13
|
+
declare function RangeParser(size: number, str: string, options?: RangeParser.Options): RangeParser.Result | RangeParser.Ranges;
|
|
14
|
+
|
|
15
|
+
declare namespace RangeParser {
|
|
16
|
+
interface Ranges extends Array<Range> {
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
interface Range {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
}
|
|
23
|
+
interface Options {
|
|
24
|
+
/**
|
|
25
|
+
* The "combine" option can be set to `true` and overlapping & adjacent ranges
|
|
26
|
+
* will be combined into a single range.
|
|
27
|
+
*/
|
|
28
|
+
combine?: boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
type ResultUnsatisfiable = -1;
|
|
31
|
+
type ResultInvalid = -2;
|
|
32
|
+
type Result = ResultUnsatisfiable | ResultInvalid;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export = RangeParser;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Type definitions for serve-static 1.13
|
|
2
|
+
// Project: https://github.com/expressjs/serve-static
|
|
3
|
+
// Definitions by: Uros Smolnik <https://github.com/urossmolnik>
|
|
4
|
+
// Linus Unnebäck <https://github.com/LinusU>
|
|
5
|
+
// Devansh Jethmalani <https://github.com/devanshj>
|
|
6
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
7
|
+
// TypeScript Version: 2.3
|
|
8
|
+
|
|
9
|
+
/// <reference types="node" />
|
|
10
|
+
import * as m from '../mime';
|
|
11
|
+
import * as http from 'http';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a new middleware function to serve files from within a given root directory.
|
|
15
|
+
* The file to serve will be determined by combining req.url with the provided root directory.
|
|
16
|
+
* When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.
|
|
17
|
+
*/
|
|
18
|
+
declare function serveStatic<R extends http.ServerResponse>(
|
|
19
|
+
root: string,
|
|
20
|
+
options?: serveStatic.ServeStaticOptions<R>
|
|
21
|
+
): serveStatic.RequestHandler<R>;
|
|
22
|
+
|
|
23
|
+
declare namespace serveStatic {
|
|
24
|
+
var mime: typeof m;
|
|
25
|
+
interface ServeStaticOptions<R extends http.ServerResponse = http.ServerResponse> {
|
|
26
|
+
/**
|
|
27
|
+
* Enable or disable setting Cache-Control response header, defaults to true.
|
|
28
|
+
* Disabling this will ignore the immutable and maxAge options.
|
|
29
|
+
*/
|
|
30
|
+
cacheControl?: boolean | undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
|
|
34
|
+
* Note this check is done on the path itself without checking if the path actually exists on the disk.
|
|
35
|
+
* If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny").
|
|
36
|
+
* The default value is 'ignore'.
|
|
37
|
+
* 'allow' No special treatment for dotfiles
|
|
38
|
+
* 'deny' Send a 403 for any request for a dotfile
|
|
39
|
+
* 'ignore' Pretend like the dotfile does not exist and call next()
|
|
40
|
+
*/
|
|
41
|
+
dotfiles?: string | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Enable or disable etag generation, defaults to true.
|
|
45
|
+
*/
|
|
46
|
+
etag?: boolean | undefined;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.
|
|
50
|
+
* The first that exists will be served. Example: ['html', 'htm'].
|
|
51
|
+
* The default value is false.
|
|
52
|
+
*/
|
|
53
|
+
extensions?: string[] | false | undefined;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Let client errors fall-through as unhandled requests, otherwise forward a client error.
|
|
57
|
+
* The default value is true.
|
|
58
|
+
*/
|
|
59
|
+
fallthrough?: boolean | undefined;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Enable or disable the immutable directive in the Cache-Control response header.
|
|
63
|
+
* If enabled, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.
|
|
64
|
+
*/
|
|
65
|
+
immutable?: boolean | undefined;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* By default this module will send "index.html" files in response to a request on a directory.
|
|
69
|
+
* To disable this set false or to supply a new index pass a string or an array in preferred order.
|
|
70
|
+
*/
|
|
71
|
+
index?: boolean | string | string[] | undefined;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.
|
|
75
|
+
*/
|
|
76
|
+
lastModified?: boolean | undefined;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.
|
|
80
|
+
*/
|
|
81
|
+
maxAge?: number | string | undefined;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Redirect to trailing "/" when the pathname is a dir. Defaults to true.
|
|
85
|
+
*/
|
|
86
|
+
redirect?: boolean | undefined;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Function to set custom headers on response. Alterations to the headers need to occur synchronously.
|
|
90
|
+
* The function is called as fn(res, path, stat), where the arguments are:
|
|
91
|
+
* res the response object
|
|
92
|
+
* path the file path that is being sent
|
|
93
|
+
* stat the stat object of the file that is being sent
|
|
94
|
+
*/
|
|
95
|
+
setHeaders?: ((res: R, path: string, stat: any) => any) | undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface RequestHandler<R extends http.ServerResponse> {
|
|
99
|
+
(request: http.IncomingMessage, response: R, next: () => void): any;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface RequestHandlerConstructor<R extends http.ServerResponse> {
|
|
103
|
+
(root: string, options?: ServeStaticOptions<R>): RequestHandler<R>;
|
|
104
|
+
mime: typeof m;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export = serveStatic;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const server_1 = require("@umijs/server");
|
|
13
|
+
const utils_1 = require("@umijs/utils");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const clearTmp_1 = require("../utils/clearTmp");
|
|
17
|
+
const getBabelOpts_1 = require("./dev/getBabelOpts");
|
|
18
|
+
const getMarkupArgs_1 = require("./dev/getMarkupArgs");
|
|
19
|
+
const bundlerWebpack = (0, utils_1.importLazy)('@umijs/bundler-webpack');
|
|
20
|
+
const bundlerVite = (0, utils_1.importLazy)('@umijs/bundler-vite');
|
|
21
|
+
exports.default = (api) => {
|
|
22
|
+
api.registerCommand({
|
|
23
|
+
name: 'build',
|
|
24
|
+
description: 'build app for production',
|
|
25
|
+
details: `
|
|
26
|
+
umi build
|
|
27
|
+
|
|
28
|
+
# build without compression
|
|
29
|
+
COMPRESS=none umi build
|
|
30
|
+
|
|
31
|
+
# clean and build
|
|
32
|
+
umi build --clean
|
|
33
|
+
`,
|
|
34
|
+
fn: function () {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
// clear tmp except cache
|
|
37
|
+
(0, clearTmp_1.clearTmp)(api.paths.absTmpPath);
|
|
38
|
+
// check package.json
|
|
39
|
+
yield api.applyPlugins({
|
|
40
|
+
key: 'onCheckPkgJSON',
|
|
41
|
+
args: {
|
|
42
|
+
origin: null,
|
|
43
|
+
current: api.appData.pkg,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
// generate files
|
|
47
|
+
function generate(opts) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
yield api.applyPlugins({
|
|
50
|
+
key: 'onGenerateFiles',
|
|
51
|
+
args: {
|
|
52
|
+
files: opts.files || null,
|
|
53
|
+
isFirstTime: opts.isFirstTime,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
yield generate({
|
|
59
|
+
isFirstTime: true,
|
|
60
|
+
});
|
|
61
|
+
yield api.applyPlugins({
|
|
62
|
+
key: 'onBeforeCompiler',
|
|
63
|
+
});
|
|
64
|
+
// build
|
|
65
|
+
// TODO: support watch mode
|
|
66
|
+
const { babelPreset, beforeBabelPlugins, beforeBabelPresets, extraBabelPlugins, extraBabelPresets, } = yield (0, getBabelOpts_1.getBabelOpts)({ api });
|
|
67
|
+
const chainWebpack = (memo, args) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
yield api.applyPlugins({
|
|
69
|
+
key: 'chainWebpack',
|
|
70
|
+
type: api.ApplyPluginsType.modify,
|
|
71
|
+
initialValue: memo,
|
|
72
|
+
args,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
const modifyWebpackConfig = (memo, args) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return yield api.applyPlugins({
|
|
77
|
+
key: 'modifyWebpackConfig',
|
|
78
|
+
initialValue: memo,
|
|
79
|
+
args,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
const modifyViteConfig = (memo, args) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return yield api.applyPlugins({
|
|
84
|
+
key: 'modifyViteConfig',
|
|
85
|
+
initialValue: memo,
|
|
86
|
+
args,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const opts = Object.assign(Object.assign({ config: api.config, cwd: api.cwd, entry: {
|
|
90
|
+
umi: (0, path_1.join)(api.paths.absTmpPath, 'umi.ts'),
|
|
91
|
+
} }, (api.args.vite
|
|
92
|
+
? { modifyViteConfig }
|
|
93
|
+
: { babelPreset, chainWebpack, modifyWebpackConfig })), { beforeBabelPlugins,
|
|
94
|
+
beforeBabelPresets,
|
|
95
|
+
extraBabelPlugins,
|
|
96
|
+
extraBabelPresets,
|
|
97
|
+
onBuildComplete(opts) {
|
|
98
|
+
api.applyPlugins({
|
|
99
|
+
key: 'onBuildComplete',
|
|
100
|
+
args: opts,
|
|
101
|
+
});
|
|
102
|
+
}, clean: api.args.clean });
|
|
103
|
+
if (api.args.vite) {
|
|
104
|
+
yield bundlerVite.build(opts);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
yield bundlerWebpack.build(opts);
|
|
108
|
+
}
|
|
109
|
+
// generate html
|
|
110
|
+
const { vite } = api.args;
|
|
111
|
+
const markupArgs = yield (0, getMarkupArgs_1.getMarkupArgs)({ api });
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
const markup = yield (0, server_1.getMarkup)(Object.assign(Object.assign({}, markupArgs), { scripts: ['/umi.js'].concat(markupArgs.scripts), esmScript: !!opts.config.esm || vite, path: '/' }));
|
|
114
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(api.paths.absOutputPath, 'index.html'), markup, 'utf-8');
|
|
115
|
+
utils_1.logger.event('build index.html');
|
|
116
|
+
// print size
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const list_1 = require("./list");
|
|
13
|
+
const remove_1 = require("./remove");
|
|
14
|
+
const set_1 = require("./set");
|
|
15
|
+
exports.default = (api) => {
|
|
16
|
+
api.registerCommand({
|
|
17
|
+
name: 'config',
|
|
18
|
+
description: 'umi config cli',
|
|
19
|
+
details: `
|
|
20
|
+
# umi configs
|
|
21
|
+
$ umi config [type] [name] [value]
|
|
22
|
+
|
|
23
|
+
# List configs
|
|
24
|
+
$ umi config list
|
|
25
|
+
|
|
26
|
+
# Get the specific config
|
|
27
|
+
$ umi config list --name history
|
|
28
|
+
$ umi config get history
|
|
29
|
+
|
|
30
|
+
# Set the specific config (only local config) [beta]
|
|
31
|
+
$ umi config set history "{type:'hash'}"
|
|
32
|
+
|
|
33
|
+
# Remove the specific config (only local config) [beta]
|
|
34
|
+
$ umi config remove history
|
|
35
|
+
$ umi config r history
|
|
36
|
+
`.trim(),
|
|
37
|
+
fn({ args }) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { _, all = false } = args;
|
|
40
|
+
const [command, name, value] = _;
|
|
41
|
+
switch (command) {
|
|
42
|
+
case 'list':
|
|
43
|
+
(0, list_1.list)(all ? api.config : api.userConfig, args.name || '');
|
|
44
|
+
break;
|
|
45
|
+
case 'get':
|
|
46
|
+
(0, list_1.list)(api.config, name);
|
|
47
|
+
break;
|
|
48
|
+
case 'set':
|
|
49
|
+
(0, set_1.set)(api.appData.mainConfigFile, name, value);
|
|
50
|
+
break;
|
|
51
|
+
case 'remove':
|
|
52
|
+
case 'r':
|
|
53
|
+
(0, remove_1.remove)(api.appData.mainConfigFile, name);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported sub command ${command} for umi config.`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.list = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
function list(config, name) {
|
|
6
|
+
const getValue = (value) => {
|
|
7
|
+
if (typeof value !== 'function') {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return utils_1.chalk.yellow('The value data type does not support the view');
|
|
11
|
+
};
|
|
12
|
+
const print = (key) => {
|
|
13
|
+
console.log(` - ${utils_1.chalk.blue(`[key: ${key}]`)}`, getValue(config[key]));
|
|
14
|
+
console.log();
|
|
15
|
+
};
|
|
16
|
+
console.log();
|
|
17
|
+
console.log(` Configs:`);
|
|
18
|
+
console.log();
|
|
19
|
+
if (name) {
|
|
20
|
+
if (!config[name]) {
|
|
21
|
+
// current key not existed
|
|
22
|
+
throw new Error(`key ${name} not found`);
|
|
23
|
+
}
|
|
24
|
+
print(name);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// list all
|
|
28
|
+
Object.keys(config).forEach((key) => {
|
|
29
|
+
print(key);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
console.log();
|
|
33
|
+
}
|
|
34
|
+
exports.list = list;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function remove(mainConfigFile: string, name: string): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.remove = void 0;
|
|
7
|
+
const ast_1 = require("@umijs/ast");
|
|
8
|
+
const prettier_1 = __importDefault(require("@umijs/utils/compiled/prettier"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
function remove(mainConfigFile, name) {
|
|
11
|
+
const ast = (0, ast_1.getASTByFilePath)(mainConfigFile);
|
|
12
|
+
if (!ast)
|
|
13
|
+
return;
|
|
14
|
+
const generateCode = (0, ast_1.generate)((0, ast_1.removeConfigByName)(ast, name));
|
|
15
|
+
const printStr = prettier_1.default.format(generateCode, {
|
|
16
|
+
parser: 'typescript',
|
|
17
|
+
});
|
|
18
|
+
(0, fs_1.writeFileSync)(mainConfigFile, printStr, 'utf-8');
|
|
19
|
+
console.log(`remove config:${name} on ${mainConfigFile}`);
|
|
20
|
+
}
|
|
21
|
+
exports.remove = remove;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function set(mainConfigFile: string, name: string, value: any): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.set = void 0;
|
|
7
|
+
const ast_1 = require("@umijs/ast");
|
|
8
|
+
const prettier_1 = __importDefault(require("@umijs/utils/compiled/prettier"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
function set(mainConfigFile, name, value) {
|
|
11
|
+
const ast = (0, ast_1.getASTByFilePath)(mainConfigFile);
|
|
12
|
+
if (!ast)
|
|
13
|
+
return;
|
|
14
|
+
const generateCode = (0, ast_1.generate)((0, ast_1.setConfigByName)(ast, name, value));
|
|
15
|
+
const printStr = prettier_1.default.format(generateCode, {
|
|
16
|
+
parser: 'typescript',
|
|
17
|
+
});
|
|
18
|
+
(0, fs_1.writeFileSync)(mainConfigFile, printStr, 'utf-8');
|
|
19
|
+
console.log(`set config:${name} on ${mainConfigFile}`);
|
|
20
|
+
}
|
|
21
|
+
exports.set = set;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createRouteMiddleware = void 0;
|
|
13
|
+
const server_1 = require("@umijs/server");
|
|
14
|
+
const getMarkupArgs_1 = require("./getMarkupArgs");
|
|
15
|
+
// TODO: extract to bundler-vite
|
|
16
|
+
// refer: https://vitejs.dev/guide/backend-integration.html#backend-integration
|
|
17
|
+
const viteRefreshScript = `
|
|
18
|
+
import RefreshRuntime from '/@react-refresh'
|
|
19
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
|
20
|
+
window.$RefreshReg$ = () => {}
|
|
21
|
+
window.$RefreshSig$ = () => (type) => type
|
|
22
|
+
window.__vite_plugin_react_preamble_installed__ = true
|
|
23
|
+
`;
|
|
24
|
+
function createRouteMiddleware(opts) {
|
|
25
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { vite } = opts.api.args;
|
|
27
|
+
const markupArgs = yield (0, getMarkupArgs_1.getMarkupArgs)(opts);
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const requestHandler = yield (0, server_1.createRequestHandler)(Object.assign(Object.assign({}, markupArgs), { scripts: (vite
|
|
30
|
+
? [viteRefreshScript, '/@vite/client', '/.umi/umi.ts']
|
|
31
|
+
: ['/umi.js']).concat(markupArgs.scripts), esmScript: vite }));
|
|
32
|
+
requestHandler(req, res, next);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.createRouteMiddleware = createRouteMiddleware;
|