akfun 5.2.9 → 5.2.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/package.json
CHANGED
|
@@ -5,7 +5,7 @@ module.exports = {
|
|
|
5
5
|
'@babel/preset-env',
|
|
6
6
|
{
|
|
7
7
|
loose: true,
|
|
8
|
-
modules: false
|
|
8
|
+
modules: false // 是否启用将ES6模块语法转换为其他模块类型的功能,当前设置为false,以便webpack进行tree shaking。
|
|
9
9
|
/*
|
|
10
10
|
备注:后续升级babel版本时,再启用此配置
|
|
11
11
|
useBuiltIns: 'usage', // 按需引入 polyfill,替代 @babel/polyfill
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Babel 插件:自动在 React 组件的最外层元素添加 data-scope 属性
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* 使用场景:
|
|
5
5
|
* - 在构建 React 组件时,自动为组件的根元素添加 data-scope 属性
|
|
6
6
|
* - 支持函数组件和类组件
|
|
@@ -12,18 +12,17 @@ module.exports = function ({ types: t }) {
|
|
|
12
12
|
*/
|
|
13
13
|
function returnsJSX(path) {
|
|
14
14
|
const body = path.get('body');
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
if (body.isBlockStatement()) {
|
|
17
17
|
// 检查函数体中是否有返回 JSX 的语句
|
|
18
18
|
let hasJSXReturn = false;
|
|
19
19
|
body.traverse({
|
|
20
20
|
ReturnStatement(returnPath) {
|
|
21
21
|
const argument = returnPath.get('argument');
|
|
22
|
-
if (
|
|
23
|
-
argument.
|
|
24
|
-
argument.isJSXFragment() ||
|
|
25
|
-
|
|
26
|
-
)) {
|
|
22
|
+
if (
|
|
23
|
+
argument.node &&
|
|
24
|
+
(argument.isJSXElement() || argument.isJSXFragment() || argument.isArrayExpression())
|
|
25
|
+
) {
|
|
27
26
|
hasJSXReturn = true;
|
|
28
27
|
returnPath.stop();
|
|
29
28
|
}
|
|
@@ -34,7 +33,7 @@ module.exports = function ({ types: t }) {
|
|
|
34
33
|
// 箭头函数直接返回 JSX
|
|
35
34
|
return true;
|
|
36
35
|
}
|
|
37
|
-
|
|
36
|
+
|
|
38
37
|
return false;
|
|
39
38
|
}
|
|
40
39
|
|
|
@@ -47,15 +46,12 @@ module.exports = function ({ types: t }) {
|
|
|
47
46
|
|
|
48
47
|
// 检查是否已经存在 data-scope 属性
|
|
49
48
|
const hasDataScope = attributes.some(
|
|
50
|
-
attr => t.isJSXAttribute(attr) && attr.name.name === 'data-scope'
|
|
49
|
+
(attr) => t.isJSXAttribute(attr) && attr.name.name === 'data-scope'
|
|
51
50
|
);
|
|
52
51
|
|
|
53
52
|
if (!hasDataScope) {
|
|
54
53
|
// 创建 data-scope 属性
|
|
55
|
-
const dataScopeAttr = t.jsxAttribute(
|
|
56
|
-
t.jsxIdentifier('data-scope'),
|
|
57
|
-
t.stringLiteral('')
|
|
58
|
-
);
|
|
54
|
+
const dataScopeAttr = t.jsxAttribute(t.jsxIdentifier('data-scope'), t.stringLiteral(''));
|
|
59
55
|
// 添加到属性列表的开头
|
|
60
56
|
attributes.unshift(dataScopeAttr);
|
|
61
57
|
}
|
|
@@ -66,7 +62,7 @@ module.exports = function ({ types: t }) {
|
|
|
66
62
|
*/
|
|
67
63
|
function processReturnStatement(path) {
|
|
68
64
|
const argument = path.get('argument');
|
|
69
|
-
|
|
65
|
+
|
|
70
66
|
if (!argument.node) {
|
|
71
67
|
return;
|
|
72
68
|
}
|
|
@@ -146,7 +142,7 @@ module.exports = function ({ types: t }) {
|
|
|
146
142
|
}
|
|
147
143
|
|
|
148
144
|
const body = path.get('body');
|
|
149
|
-
|
|
145
|
+
|
|
150
146
|
// 处理函数体中的返回语句
|
|
151
147
|
if (body.isBlockStatement()) {
|
|
152
148
|
body.traverse({
|
|
@@ -185,4 +181,3 @@ module.exports = function ({ types: t }) {
|
|
|
185
181
|
}
|
|
186
182
|
};
|
|
187
183
|
};
|
|
188
|
-
|
package/src/rollup/build.js
CHANGED
|
@@ -68,6 +68,7 @@ module.exports = function (config, envConfig, _rollupConfig, _consoleTag) {
|
|
|
68
68
|
curRollupConfig.output.map((outputItem) => {
|
|
69
69
|
if (outputItem.notCompressed) {
|
|
70
70
|
// 不压缩代码
|
|
71
|
+
delete outputItem.notCompressed; // 剔除掉 rollup 不能识别的配置
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
if (!outputItem.plugins) {
|
|
@@ -143,7 +143,7 @@ module.exports = function (curConfig, curEnvConfig) {
|
|
|
143
143
|
{
|
|
144
144
|
file: resolveToCurrentDist(`${curFileName}.${buildFormat}.js`, curEnvConfig.outDir),
|
|
145
145
|
format: buildFormat,
|
|
146
|
-
notCompressed: true
|
|
146
|
+
notCompressed: true // 不压缩代码
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
file: resolveToCurrentDist(`${curFileName}.${buildFormat}.min.js`, curEnvConfig.outDir),
|
|
@@ -39,6 +39,9 @@ module.exports = (_curEnvConfig, _akfunConfig, buildMode = 'build') => {
|
|
|
39
39
|
// 获取当前项目目录
|
|
40
40
|
const curProjectDir = getProjectDir(curWebpackConfig.projectDir);
|
|
41
41
|
|
|
42
|
+
// 剔除掉 babel-loader 不需要的配置
|
|
43
|
+
delete babelConfig.extensions;
|
|
44
|
+
|
|
42
45
|
// 判断是否有自定义 Babel plugins
|
|
43
46
|
if (isArray(curWebpackConfig.babelPlugins)) {
|
|
44
47
|
// 添加自定义babel插件
|