@umijs/preset-umi 4.0.5 → 4.0.6
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/dist/commands/dev/dev.js +6 -2
- package/dist/commands/lint.js +4 -1
- package/dist/commands/preview.js +1 -1
- package/dist/features/apiRoute/apiRoute.js +0 -1
- package/dist/features/clickToComponent/clickToComponent.d.ts +3 -0
- package/dist/features/clickToComponent/clickToComponent.js +58 -0
- package/dist/features/ssr/builder/css-loader.js +2 -2
- package/dist/features/tmpFiles/routes.d.ts +9 -0
- package/dist/features/tmpFiles/routes.js +35 -3
- package/dist/index.js +1 -0
- package/package.json +11 -10
package/dist/commands/dev/dev.js
CHANGED
|
@@ -235,12 +235,16 @@ PORT=8888 umi dev
|
|
|
235
235
|
extraBabelPresets,
|
|
236
236
|
beforeMiddlewares: [].concat([
|
|
237
237
|
...beforeMiddlewares,
|
|
238
|
-
faviconMiddleware_1.faviconMiddleware,
|
|
239
238
|
]),
|
|
240
239
|
// vite 模式使用 ./plugins/ViteHtmlPlugin.ts 处理
|
|
241
240
|
afterMiddlewares: enableVite
|
|
242
241
|
? []
|
|
243
|
-
: middlewares.concat(
|
|
242
|
+
: middlewares.concat([
|
|
243
|
+
(0, createRouteMiddleware_1.createRouteMiddleware)({ api }),
|
|
244
|
+
// 放置 favicon 在 webpack middleware 之后,兼容 public 目录下有 favicon.ico 的场景
|
|
245
|
+
// ref: https://github.com/umijs/umi/issues/8024
|
|
246
|
+
faviconMiddleware_1.faviconMiddleware,
|
|
247
|
+
]),
|
|
244
248
|
onDevCompileDone(opts) {
|
|
245
249
|
debouncedPrintMemoryUsage;
|
|
246
250
|
// debouncedPrintMemoryUsage();
|
package/dist/commands/lint.js
CHANGED
|
@@ -17,11 +17,14 @@ umi lint --stylelint-only
|
|
|
17
17
|
|
|
18
18
|
# automatically fix, where possible
|
|
19
19
|
umi lint --fix
|
|
20
|
+
|
|
21
|
+
# disable reporting on warnings
|
|
22
|
+
umi lint --quiet
|
|
20
23
|
`,
|
|
21
24
|
fn: async function () {
|
|
22
25
|
// re-parse cli args to process boolean flags, for get the lint-staged args
|
|
23
26
|
const args = (0, utils_1.yParser)(process.argv.slice(3), {
|
|
24
|
-
boolean: ['fix', 'eslint-only', 'stylelint-only'],
|
|
27
|
+
boolean: ['quiet', 'fix', 'eslint-only', 'stylelint-only'],
|
|
25
28
|
});
|
|
26
29
|
try {
|
|
27
30
|
require.resolve('@umijs/lint/package.json');
|
package/dist/commands/preview.js
CHANGED
|
@@ -92,7 +92,7 @@ umi preview --port [port]
|
|
|
92
92
|
server.listen(port, () => {
|
|
93
93
|
const host = api.args.host && api.args.host !== '0.0.0.0'
|
|
94
94
|
? api.args.host
|
|
95
|
-
: '
|
|
95
|
+
: 'localhost';
|
|
96
96
|
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
97
97
|
});
|
|
98
98
|
},
|
|
@@ -48,7 +48,6 @@ exports.default = (api) => {
|
|
|
48
48
|
return false;
|
|
49
49
|
const config = api.userConfig.apiRoute;
|
|
50
50
|
if (!config) {
|
|
51
|
-
utils_1.logger.warn('Directory ./src/api exists, but config.apiRoute is not set. API route feature will not be enabled!');
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
54
53
|
if (!config.platform) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@umijs/utils");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
exports.default = (api) => {
|
|
6
|
+
api.describe({
|
|
7
|
+
key: 'clickToComponent',
|
|
8
|
+
config: {
|
|
9
|
+
schema(joi) {
|
|
10
|
+
return joi.object({
|
|
11
|
+
editor: joi.string(),
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
enableBy: api.EnableBy.config,
|
|
16
|
+
});
|
|
17
|
+
const pkgPath = (0, path_1.dirname)(require.resolve('click-to-react-component'));
|
|
18
|
+
api.modifyConfig((memo) => {
|
|
19
|
+
memo.alias['click-to-react-component'] = pkgPath;
|
|
20
|
+
return memo;
|
|
21
|
+
});
|
|
22
|
+
api.modifyAppData((memo) => {
|
|
23
|
+
memo.clickToComponent = {
|
|
24
|
+
pkgPath,
|
|
25
|
+
version: '1.0.8',
|
|
26
|
+
};
|
|
27
|
+
return memo;
|
|
28
|
+
});
|
|
29
|
+
api.onGenerateFiles({
|
|
30
|
+
name: 'clickToComponent',
|
|
31
|
+
fn: () => {
|
|
32
|
+
api.writeTmpFile({
|
|
33
|
+
path: 'runtime.tsx',
|
|
34
|
+
content: `
|
|
35
|
+
import { ClickToComponent } from 'click-to-react-component';
|
|
36
|
+
import React from 'react';
|
|
37
|
+
export function rootContainer(container, opts) {
|
|
38
|
+
return React.createElement(
|
|
39
|
+
(props) => {
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<ClickToComponent editor="${api.config.clickToComponent.editor || 'vscode'}"/>
|
|
43
|
+
{props.children}
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
opts,
|
|
48
|
+
container,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
api.addRuntimePlugin(() => [
|
|
56
|
+
(0, utils_1.winPath)((0, path_1.join)(api.paths.absTmpPath, 'plugin-clickToComponent/runtime.tsx')),
|
|
57
|
+
]);
|
|
58
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cssLoader = exports.getClassNames = exports.hashString = exports.ensureLastSlash = void 0;
|
|
4
|
-
const
|
|
4
|
+
const parcelCSS_1 = require("@umijs/bundler-webpack/dist/parcelCSS");
|
|
5
5
|
const utils_1 = require("@umijs/utils");
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
@@ -18,7 +18,7 @@ exports.hashString = hashString;
|
|
|
18
18
|
function getClassNames(code, filename) {
|
|
19
19
|
// why use Parcel CSS?
|
|
20
20
|
// ref: https://github.com/indooorsman/esbuild-css-modules-plugin
|
|
21
|
-
const { exports } =
|
|
21
|
+
const { exports } = parcelCSS_1.parcelCSS.transform({
|
|
22
22
|
filename,
|
|
23
23
|
code,
|
|
24
24
|
minify: false,
|
|
@@ -10,3 +10,12 @@ export declare function getRouteComponents(opts: {
|
|
|
10
10
|
prefix: string;
|
|
11
11
|
api: IApi;
|
|
12
12
|
}): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* transform component into webpack chunkName
|
|
16
|
+
* @export
|
|
17
|
+
* @param {string} component component path
|
|
18
|
+
* @param {string} [cwd] current root path
|
|
19
|
+
* @return {*} {string}
|
|
20
|
+
*/
|
|
21
|
+
export declare function componentToChunkName(component: string, cwd?: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRouteComponents = exports.getRoutes = exports.getApiRoutes = void 0;
|
|
3
|
+
exports.componentToChunkName = exports.getRouteComponents = exports.getRoutes = exports.getApiRoutes = void 0;
|
|
4
4
|
const core_1 = require("@umijs/core");
|
|
5
5
|
const utils_1 = require("@umijs/utils");
|
|
6
6
|
const fs_1 = require("fs");
|
|
@@ -190,11 +190,43 @@ async function getRouteComponents(opts) {
|
|
|
190
190
|
const path = (0, path_1.isAbsolute)(route.file) || route.file.startsWith('@/')
|
|
191
191
|
? route.file
|
|
192
192
|
: `${opts.prefix}${route.file}`;
|
|
193
|
+
const webpackChunkName = componentToChunkName(path, opts.api.cwd);
|
|
193
194
|
return useSuspense
|
|
194
|
-
? `'${key}': React.lazy(() => import(/* webpackChunkName: "${
|
|
195
|
-
: `'${key}': () => import(/* webpackChunkName: "${
|
|
195
|
+
? `'${key}': React.lazy(() => import(/* webpackChunkName: "${webpackChunkName}" */'${(0, utils_1.winPath)(path)}')),`
|
|
196
|
+
: `'${key}': () => import(/* webpackChunkName: "${webpackChunkName}" */'${(0, utils_1.winPath)(path)}'),`;
|
|
196
197
|
})
|
|
197
198
|
.join('\n');
|
|
198
199
|
return `{\n${imports}\n}`;
|
|
199
200
|
}
|
|
200
201
|
exports.getRouteComponents = getRouteComponents;
|
|
202
|
+
function lastSlash(str) {
|
|
203
|
+
return str[str.length - 1] === '/' ? str : `${str}/`;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
*
|
|
207
|
+
* transform component into webpack chunkName
|
|
208
|
+
* @export
|
|
209
|
+
* @param {string} component component path
|
|
210
|
+
* @param {string} [cwd] current root path
|
|
211
|
+
* @return {*} {string}
|
|
212
|
+
*/
|
|
213
|
+
function componentToChunkName(component, cwd) {
|
|
214
|
+
return typeof component === 'string'
|
|
215
|
+
? component
|
|
216
|
+
.replace(new RegExp(`^${utils_1.lodash.escapeRegExp(lastSlash((0, utils_1.winPath)(cwd || '/')))}`), '')
|
|
217
|
+
.replace(/^.(\/|\\)/, '')
|
|
218
|
+
.replace(/(\/|\\)/g, '__')
|
|
219
|
+
.replace(/\.jsx?$/, '')
|
|
220
|
+
.replace(/\.tsx?$/, '')
|
|
221
|
+
.replace(/\.vue?$/, '')
|
|
222
|
+
.replace(/^src__/, '')
|
|
223
|
+
.replace(/\.\.__/g, '')
|
|
224
|
+
// 约定式路由的 [ 会导致 webpack 的 code splitting 失败
|
|
225
|
+
// ref: https://github.com/umijs/umi/issues/4155
|
|
226
|
+
.replace(/[\[\]]/g, '')
|
|
227
|
+
// 插件层的文件也可能是路由组件,比如 plugin-layout 插件
|
|
228
|
+
.replace(/^.umi-production__/, 't__')
|
|
229
|
+
.replace(/^pages__/, 'p__')
|
|
230
|
+
: '';
|
|
231
|
+
}
|
|
232
|
+
exports.componentToChunkName = componentToChunkName;
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ exports.default = () => {
|
|
|
28
28
|
require.resolve('./features/vite/vite'),
|
|
29
29
|
require.resolve('./features/apiRoute/apiRoute'),
|
|
30
30
|
require.resolve('./features/monorepo/redirect'),
|
|
31
|
+
require.resolve('./features/clickToComponent/clickToComponent'),
|
|
31
32
|
// commands
|
|
32
33
|
require.resolve('./commands/build'),
|
|
33
34
|
require.resolve('./commands/config/config'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"description": "@umijs/preset-umi",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@types/multer": "1.4.7",
|
|
29
|
-
"@umijs/ast": "4.0.
|
|
30
|
-
"@umijs/babel-preset-umi": "4.0.
|
|
31
|
-
"@umijs/bundler-utils": "4.0.
|
|
32
|
-
"@umijs/bundler-vite": "4.0.
|
|
33
|
-
"@umijs/bundler-webpack": "4.0.
|
|
34
|
-
"@umijs/core": "4.0.
|
|
35
|
-
"@umijs/renderer-react": "4.0.
|
|
36
|
-
"@umijs/server": "4.0.
|
|
37
|
-
"@umijs/utils": "4.0.
|
|
29
|
+
"@umijs/ast": "4.0.6",
|
|
30
|
+
"@umijs/babel-preset-umi": "4.0.6",
|
|
31
|
+
"@umijs/bundler-utils": "4.0.6",
|
|
32
|
+
"@umijs/bundler-vite": "4.0.6",
|
|
33
|
+
"@umijs/bundler-webpack": "4.0.6",
|
|
34
|
+
"@umijs/core": "4.0.6",
|
|
35
|
+
"@umijs/renderer-react": "4.0.6",
|
|
36
|
+
"@umijs/server": "4.0.6",
|
|
37
|
+
"@umijs/utils": "4.0.6",
|
|
38
|
+
"click-to-react-component": "^1.0.8",
|
|
38
39
|
"core-js": "3.22.4",
|
|
39
40
|
"current-script-polyfill": "1.0.0",
|
|
40
41
|
"enhanced-resolve": "5.9.3",
|