mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 09:41:57 +00:00
fix: 🐛 解决 Rax 出码到小程序的时候 require(xxx) 语句不能被编译的问题
This commit is contained in:
parent
42e41bbd12
commit
332a473cd2
@ -11,6 +11,7 @@ import {
|
||||
DataSourceConfig,
|
||||
isJSExpression,
|
||||
isJSFunction,
|
||||
JSExpression,
|
||||
} from '../../../types';
|
||||
|
||||
import { generateUnknownType } from '../../../utils/compositeType';
|
||||
@ -37,23 +38,30 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const dataSourceItems: DataSourceConfig[] = (dataSourceConfig && dataSourceConfig.list) || [];
|
||||
const dataSourceEngineOptions = { runtimeConfig: true };
|
||||
if (dataSourceItems.length > 0) {
|
||||
Object.assign(dataSourceEngineOptions, {
|
||||
requestHandlersMap: dataSourceItems.reduce(
|
||||
(handlers, ds) =>
|
||||
ds.type in handlers && ds.type !== 'custom'
|
||||
? handlers
|
||||
: {
|
||||
...handlers,
|
||||
[ds.type]: {
|
||||
type: 'JSExpression',
|
||||
value:
|
||||
`require('@ali/lowcode-datasource-engine/handlers/${changeCase.kebabCase(ds.type)}')` +
|
||||
(ds.type === 'urlParams' ? '({ search: this.props.location.search })' : ''),
|
||||
},
|
||||
},
|
||||
{} as Record<string, CompositeValue>,
|
||||
),
|
||||
const requestHandlersMap = {} as Record<string, JSExpression>;
|
||||
|
||||
dataSourceItems.forEach((ds) => {
|
||||
if (!(ds.type in requestHandlersMap) && ds.type !== 'custom') {
|
||||
const handlerName = '__$$' + changeCase.camelCase(ds.type) + 'RequestHandler';
|
||||
|
||||
requestHandlersMap[ds.type] = {
|
||||
type: 'JSExpression',
|
||||
value: handlerName + (ds.type === 'urlParams' ? '({ search: this.props.location.search })' : ''),
|
||||
};
|
||||
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.JSX,
|
||||
name: COMMON_CHUNK_NAME.ExternalDepsImport,
|
||||
content: `
|
||||
import ${handlerName} from '@ali/lowcode-datasource-engine/handlers/${changeCase.kebabCase(ds.type)}';
|
||||
`,
|
||||
linkAfter: [],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Object.assign(dataSourceEngineOptions, { requestHandlersMap });
|
||||
}
|
||||
|
||||
next.chunks.push({
|
||||
|
||||
@ -9,6 +9,10 @@ import Text from 'rax-text';
|
||||
|
||||
import Image from 'rax-image';
|
||||
|
||||
import __$$urlParamsRequestHandler from '@ali/lowcode-datasource-engine/handlers/url-params';
|
||||
|
||||
import __$$fetchRequestHandler from '@ali/lowcode-datasource-engine/handlers/fetch';
|
||||
|
||||
import { create as __$$createDataSourceEngine } from '@ali/lowcode-datasource-engine';
|
||||
|
||||
import { isMiniApp as __$$isMiniApp } from 'universal-env';
|
||||
@ -44,9 +48,9 @@ class Home$$Page extends Component {
|
||||
_dataSourceConfig = this._defineDataSourceConfig();
|
||||
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, {
|
||||
runtimeConfig: true,
|
||||
requestHandlers: {
|
||||
urlParams: require('@ali/lowcode-datasource-engine/handlers/url-params')({ search: this.props.location.search }),
|
||||
fetch: require('@ali/lowcode-datasource-engine/handlers/fetch'),
|
||||
requestHandlersMap: {
|
||||
urlParams: __$$urlParamsRequestHandler({ search: this.props.location.search }),
|
||||
fetch: __$$fetchRequestHandler,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user