@umijs/babel-preset-umi 4.0.0-rc.8 → 4.0.1
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/index.d.ts +3 -0
- package/dist/index.js +39 -10
- package/dist/plugins/stripExports.d.ts +3 -0
- package/dist/plugins/stripExports.js +109 -0
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,28 +8,51 @@ const path_1 = require("path");
|
|
|
8
8
|
const autoCSSModules_1 = __importDefault(require("./plugins/autoCSSModules"));
|
|
9
9
|
const dynamicImportNode_1 = __importDefault(require("./plugins/dynamicImportNode"));
|
|
10
10
|
const lockCoreJS_1 = __importDefault(require("./plugins/lockCoreJS"));
|
|
11
|
+
const stripExports_1 = __importDefault(require("./plugins/stripExports"));
|
|
11
12
|
exports.default = (_context, opts) => {
|
|
12
13
|
return {
|
|
13
14
|
presets: [
|
|
14
15
|
[
|
|
15
16
|
require.resolve('@umijs/bundler-utils/compiled/babel/preset-env'),
|
|
16
|
-
|
|
17
|
+
{
|
|
18
|
+
bugfixes: true,
|
|
17
19
|
// 更兼容 spec,但会变慢,所以不开
|
|
18
|
-
spec: false,
|
|
20
|
+
spec: false,
|
|
19
21
|
// 推荐用 top level 的 assumptions 配置
|
|
20
|
-
loose: false,
|
|
22
|
+
loose: false,
|
|
21
23
|
// 保留 es modules 语法,交给 webpack 处理
|
|
22
|
-
modules: false,
|
|
24
|
+
modules: false,
|
|
25
|
+
debug: false,
|
|
26
|
+
useBuiltIns: 'entry',
|
|
27
|
+
corejs: (0, utils_1.getCorejsVersion)((0, path_1.join)(__dirname, '../package.json')),
|
|
23
28
|
// 没必要,遇到了应该改 targets 配置
|
|
24
|
-
forceAllTransforms: false,
|
|
29
|
+
forceAllTransforms: false,
|
|
30
|
+
ignoreBrowserslistConfig: true,
|
|
31
|
+
...opts.presetEnv,
|
|
32
|
+
},
|
|
25
33
|
],
|
|
26
34
|
[
|
|
27
35
|
require.resolve('@umijs/bundler-utils/compiled/babel/preset-react'),
|
|
28
|
-
|
|
36
|
+
{
|
|
37
|
+
runtime: 'automatic',
|
|
38
|
+
development: process.env.NODE_ENV === 'development',
|
|
39
|
+
importSource: 'react',
|
|
40
|
+
...opts.presetReact,
|
|
41
|
+
},
|
|
29
42
|
],
|
|
30
43
|
[
|
|
31
44
|
require.resolve('@umijs/bundler-utils/compiled/babel/preset-typescript'),
|
|
32
|
-
|
|
45
|
+
{
|
|
46
|
+
// 支持vue 后缀
|
|
47
|
+
allExtensions: true,
|
|
48
|
+
// 支持tsx
|
|
49
|
+
isTSX: true,
|
|
50
|
+
allowNamespaces: true,
|
|
51
|
+
allowDeclareFields: true,
|
|
52
|
+
onlyRemoveTypeImports: true,
|
|
53
|
+
optimizeConstEnums: true,
|
|
54
|
+
...opts.presetTypeScript,
|
|
55
|
+
},
|
|
33
56
|
],
|
|
34
57
|
],
|
|
35
58
|
plugins: [
|
|
@@ -78,19 +101,25 @@ exports.default = (_context, opts) => {
|
|
|
78
101
|
],
|
|
79
102
|
opts.pluginTransformRuntime && [
|
|
80
103
|
require.resolve('@umijs/bundler-utils/compiled/babel/plugin-transform-runtime'),
|
|
81
|
-
|
|
104
|
+
{
|
|
105
|
+
helpers: true,
|
|
106
|
+
regenerator: true,
|
|
82
107
|
// 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
|
|
83
|
-
useESModules: false,
|
|
108
|
+
useESModules: false,
|
|
84
109
|
// lock the version of @babel/runtime
|
|
85
110
|
// make sure we are using the correct version
|
|
86
111
|
// ref: https://github.com/babel/babel/blob/v7.16.12/packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts#L19
|
|
87
112
|
// ref: https://github.com/umijs/umi/pull/7816
|
|
88
|
-
absoluteRuntime: (0, path_1.dirname)(require.resolve('../package.json')),
|
|
113
|
+
absoluteRuntime: (0, path_1.dirname)(require.resolve('../package.json')),
|
|
114
|
+
version: `^${require('@babel/runtime/package.json').version}`,
|
|
115
|
+
...opts.pluginTransformRuntime,
|
|
116
|
+
},
|
|
89
117
|
],
|
|
90
118
|
// none official plugins
|
|
91
119
|
opts.pluginLockCoreJS && [lockCoreJS_1.default],
|
|
92
120
|
opts.pluginDynamicImportNode && [dynamicImportNode_1.default],
|
|
93
121
|
opts.pluginAutoCSSModules && [autoCSSModules_1.default],
|
|
122
|
+
opts.stripExports && [stripExports_1.default],
|
|
94
123
|
].filter(Boolean),
|
|
95
124
|
};
|
|
96
125
|
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
27
|
+
exports.default = () => {
|
|
28
|
+
return {
|
|
29
|
+
visitor: {
|
|
30
|
+
Program: {
|
|
31
|
+
enter(path, { opts }) {
|
|
32
|
+
const expressions = path.get('body');
|
|
33
|
+
const exports = (opts === null || opts === void 0 ? void 0 : opts.exports) || [];
|
|
34
|
+
expressions.forEach((exp) => {
|
|
35
|
+
if (!(t.isExportNamedDeclaration(exp) ||
|
|
36
|
+
t.isExportDefaultDeclaration(exp)))
|
|
37
|
+
return;
|
|
38
|
+
handleExportsIndividual(exp);
|
|
39
|
+
handleExportsList(exp);
|
|
40
|
+
handleExportsDefault(exp);
|
|
41
|
+
});
|
|
42
|
+
function handleExportsIndividual(path) {
|
|
43
|
+
if (!path.node)
|
|
44
|
+
return;
|
|
45
|
+
if (!t.isExportNamedDeclaration(path))
|
|
46
|
+
return;
|
|
47
|
+
if (!path.get('declaration').node)
|
|
48
|
+
return;
|
|
49
|
+
const declaration = path.get('declaration');
|
|
50
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
51
|
+
const variables = declaration.get('declarations');
|
|
52
|
+
variables.forEach((variable) => {
|
|
53
|
+
exports.includes(variable.get('id.name').node) &&
|
|
54
|
+
variable.remove();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
exports.includes(declaration.get('id.name').node) &&
|
|
59
|
+
declaration.remove();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function handleExportsList(path) {
|
|
63
|
+
if (!path.node)
|
|
64
|
+
return;
|
|
65
|
+
if (!t.isExportNamedDeclaration(path))
|
|
66
|
+
return;
|
|
67
|
+
const specifiers = path.get('specifiers');
|
|
68
|
+
if (!specifiers || specifiers.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
specifiers.forEach((specifier) => {
|
|
71
|
+
if (exports.includes(specifier.get('exported.name').node))
|
|
72
|
+
specifier.remove();
|
|
73
|
+
});
|
|
74
|
+
if (path.get('specifiers').length === 0)
|
|
75
|
+
path.remove();
|
|
76
|
+
}
|
|
77
|
+
function handleExportsDefault(path) {
|
|
78
|
+
if (!path.node)
|
|
79
|
+
return;
|
|
80
|
+
if (!t.isExportDefaultDeclaration(path))
|
|
81
|
+
return;
|
|
82
|
+
const declaration = path.get('declaration');
|
|
83
|
+
if (!declaration.node)
|
|
84
|
+
return;
|
|
85
|
+
if (exports.includes(declaration.get('name').node))
|
|
86
|
+
declaration.remove();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
exit(path) {
|
|
90
|
+
// Manually reprocess the scope to ensure that the removed declarations are updated.
|
|
91
|
+
path.scope.crawl();
|
|
92
|
+
const expressions = path.get('body');
|
|
93
|
+
expressions.forEach((exp) => {
|
|
94
|
+
if (!t.isImportDeclaration(exp))
|
|
95
|
+
return;
|
|
96
|
+
const specifiers = exp.get('specifiers');
|
|
97
|
+
specifiers.forEach((s) => {
|
|
98
|
+
const name = s.get('local.name').node;
|
|
99
|
+
if (!s.scope.getBinding(name).referenced)
|
|
100
|
+
s.remove();
|
|
101
|
+
});
|
|
102
|
+
if (exp.get('specifiers').length === 0)
|
|
103
|
+
exp.remove();
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/babel-preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Official babel preset for umi.",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/babel-preset-umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm tsc",
|
|
19
|
-
"build:deps": "
|
|
19
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
20
20
|
"dev": "pnpm build -- --watch",
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "umi-scripts jest-turbo"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/runtime": "7.17.
|
|
24
|
+
"@babel/runtime": "7.17.9",
|
|
25
25
|
"@bloomberg/record-tuple-polyfill": "0.0.4",
|
|
26
|
-
"@umijs/bundler-utils": "4.0.
|
|
27
|
-
"@umijs/utils": "4.0.
|
|
28
|
-
"core-js": "3.
|
|
26
|
+
"@umijs/bundler-utils": "4.0.1",
|
|
27
|
+
"@umijs/utils": "4.0.1",
|
|
28
|
+
"core-js": "3.22.4"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|