调整模版目录,对编译边界进行处理

This commit is contained in:
Wang Kejun 2022-08-18 11:15:39 +08:00
parent 8a7bf41bc3
commit c2f3f7e646
12 changed files with 103 additions and 50 deletions

View File

@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
const pull = require('lodash/pull');
const { assert } = require('console');
const oakRegex =

View File

@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
const pull = require('lodash/pull');
const { assert } = require('console');
function isOakNamespaceIdentifier(node, name) {
@ -38,9 +37,17 @@ module.exports = (babel) => {
: lessFileExists
? './index.less'
: './index.pc.less';
body.unshift(
t.importDeclaration([], t.stringLiteral(lessFileImport))
);
if (
(lessFileExists && !pcLessFileExists) ||
(!lessFileExists && pcLessFileExists)
) {
body.unshift(
t.importDeclaration(
[],
t.stringLiteral(lessFileImport)
)
);
}
}
},
JSXAttribute(path, state) {

View File

@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
const pull = require('lodash/pull');
const { assert } = require('console');
module.exports = (babel) => {

View File

@ -1,8 +1,7 @@
const fs = require('fs');
const { relative } = require('path');
const t = require('@babel/types');
const pull = require('lodash/pull');
const { assert } = require('console');
const t = require('@babel/types');
const generate = require('@babel/generator').default;
const parser = require("@babel/parser");

View File

@ -1,6 +1,6 @@
const fs = require('fs');
const { relative, join } = require('path');
const t = require('@babel/types');
const pull = require('lodash/pull');
const assert = require('assert');
const AppPaths = require('../web/paths');
@ -16,45 +16,92 @@ module.exports = () => {
// 在Function App前面插入router的相关代码
const functionAppNode = body[body.length - 2];
const routerDelarationNode = body[body.length - 3];
assert(t.isFunctionDeclaration(functionAppNode) && t.isIdentifier(functionAppNode.id) && functionAppNode.id.name === 'App');
assert(t.isVariableDeclaration(routerDelarationNode) && routerDelarationNode.kind === 'let'
&& t.isVariableDeclarator(routerDelarationNode.declarations[0]) && t.isIdentifier(routerDelarationNode.declarations[0].id)
&& routerDelarationNode.declarations[0].id.name === 'routers');
assert(
t.isFunctionDeclaration(functionAppNode) &&
t.isIdentifier(functionAppNode.id) &&
functionAppNode.id.name === 'App'
);
assert(
t.isVariableDeclaration(routerDelarationNode) &&
routerDelarationNode.kind === 'let' &&
t.isVariableDeclarator(
routerDelarationNode.declarations[0]
) &&
t.isIdentifier(
routerDelarationNode.declarations[0].id
) &&
routerDelarationNode.declarations[0].id.name ===
'routers'
);
const { pages } = require(join(cwd, appDir, 'src', 'app.json'));
const objs = pages.map(
(ele) => {
const relPath = ele.replace('@project', AppPaths.appRootSrc).replace('@oak-general-business', AppPaths.oakGeneralBusinessAppPath);
const { navigationBarTitleText } = require(`${relPath}.json`);
const pagePath = ele.slice(ele.indexOf('pages/') + 6, ele.length - 6);
return t.objectExpression([
t.objectProperty(t.identifier('title'), t.stringLiteral(navigationBarTitleText || '')),
t.objectProperty(t.identifier('path'), t.stringLiteral(pagePath)),
t.objectProperty(t.identifier('element'), t.callExpression(
t.memberExpression(t.identifier('React'), t.identifier('lazy')),
const { pages } = require(join(
cwd,
appDir,
'src',
'app.json'
));
const objs = pages.map((ele) => {
const relPath = ele
.replace('@project', AppPaths.appRootSrc)
.replace(
'@oak-general-business',
AppPaths.oakGeneralBusinessAppPath
);
const jsonFileExists = fs.existsSync(`${relPath}.json`);
const pagePath = ele.slice(
ele.indexOf('pages/') + 6,
ele.length - 6
);
const params = [
t.objectProperty(
t.identifier('path'),
t.stringLiteral(pagePath)
),
t.objectProperty(
t.identifier('element'),
t.callExpression(
t.memberExpression(
t.identifier('React'),
t.identifier('lazy')
),
[
t.arrowFunctionExpression(
[],
t.callExpression(
t.import(),
[
t.stringLiteral(ele)
]
)
)
t.callExpression(t.import(), [
t.stringLiteral(ele),
])
),
]
))
]);
)
),
];
if (jsonFileExists) {
const {
navigationBarTitleText,
} = require(`${relPath}.json`);
params.unshift(
t.objectProperty(
t.identifier('title'),
t.stringLiteral(
navigationBarTitleText || ''
)
)
);
}
);
return t.objectExpression(params);
});
body.splice(body.length - 2, 0, t.expressionStatement(
t.assignmentExpression(
'=',
t.identifier('routers'),
t.arrayExpression(objs)
body.splice(
body.length - 2,
0,
t.expressionStatement(
t.assignmentExpression(
'=',
t.identifier('routers'),
t.arrayExpression(objs)
)
)
));
);
}
},
},

View File

@ -1,6 +1,2 @@
@import 'tdesign-react/es/style/index.css'; // 少量公共样式
@import 'tdesign-mobile-react/es/style/index.css'; // 少量公共样式
:root {
--td-screen-xs: 576px;
}
@import 'tdesign-mobile-react/es/style/index.css'; // 少量公共样式

View File

@ -2,10 +2,10 @@ import React from 'react';
import { Routes, Route } from 'react-router-dom';
import './App.less';
import Loading from './template/Loading';
const Console = React.lazy(() => import('./template/console'));
const Frontend = React.lazy(() => import('./template/frontend'));
const NotFound = React.lazy(() => import('./template/notFound'));
import Loading from './components/Loading';
const Console = React.lazy(() => import('./components/console'));
const Frontend = React.lazy(() => import('./components/frontend'));
const NotFound = React.lazy(() => import('./components/notFound'));
const Message = React.lazy(() => import('@oak-general-business/components/message'));
const DebugPanel = React.lazy(() => import('@oak-general-business/components/func/debugPanel'));
@ -24,7 +24,7 @@ function getRoutes(routers2: Router[], namespace?: string) {
path={path}
element={
<React.Suspense fallback={<Loading />}>
<Component />
<Component namespace={namespace} />
</React.Suspense>
}
></Route>

View File

@ -11,3 +11,9 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
html,
body,
#root {
height: 100%;
}