Comments (3)
node的特性,假如最近的package.json
声明了type:"module"
, node就会按照ESM去解析, 此后commonjs的模块需要显性命名后缀:“.cjs”,而 https://github.com/alibaba/pont/blob/master/packages/pont-engine/src/utils.ts#L367 这里在生成临时文件的时候没有去检查用户的package.json
的配置(实际情况可能需要考虑更多配置的写法)。 或许朋友们可以尝试提个PR去给pont-config.json
加个配置项:moduleResolution: 'cjs' | 'esm'
。
这时候我觉得利用pnpm的workspace将pont生成出来的接口文件作为一个单独的分包。 这样的话,你无需将整个项目都声明成ESModule, 可单独的声明pont相关的包的package.json为type:commonjs
.
这里假设你和我一般怠惰:用的默认配置,一旦项目接口多了以后,生成的mods数量大约是个成百上千的规模吧,根据vite的特性,需要发送同等数量或者更多的http请求,假如配置的还是 surrounding: typeScript
,vite还要转换ts,再经过内部的文件转换服务(这里瞎说的,hh), 最终的结果就是:每次刷新会有近10s的白屏(仅在开发环境)。
故此,一个可能的建议是:单独构建一个子包: 导出生成的接口或者如pont
建议的那般挂载到window
对象上,然后导出根据项目需要封装过的axios
、fetch
或者其他请求函数,在子包中新增一个新的vite.config.ts
去单独配置, 然后使用vite
去构建库。
另外一个解决问题的思路是:配置pont,不再将mods挂载到`window`下, 单独引入接口文件使用。 这很麻烦, 但也许我们可以通过antfu的 `unplugin-auto-import` 包去做到自动引入,同时又避免因为在项目入口直接全量引入导致的首屏加载缓慢的问题。
目前我只测试了第一个方案,原来接近1700个http请求可以降低到500个左右(项目其他模块),首屏加载从15s到了3s。
from pont.
可试下 1.4.0 版本
from pont.
你解决了吗
from pont.
Related Issues (20)
- vscode-pont新版transform不生效 HOT 1
- pont start后报错Error: ENOENT: no such file or directory, open 'D:\soft\nvm\v12.14.0\node_modules\pont-engine\lib\package.json' HOT 2
- SwaggerV3 规范的数据源解析错误
- translate error, all translate engine can not access HOT 4
- 获远程接口数据失败 Error: compiler error in defname HOT 3
- 多个origins时重写CodeGenerator的getInterfaceContentInDeclaration方法不生效
- 能否在 Interface 中添加 operationId 属性
- 获远程接口数据失败 Error: compiler error in defname: DataList«task_alert_contact的实体类» HOT 2
- 修改 templatePath 对应模板中自定义接口内容,执行生成代码操作,outDir 接口文件内容不更新 HOT 1
- Extension causes high cpu load
- 所有的翻译插件失效,pont解析swagger报错 HOT 1
- 不生成 pontCore.js HOT 2
- 请问有没有nodejs api使用文档? HOT 1
- swagger V2生成baseClass时,超过两层的对象属性未读取 HOT 2
- nestjs swagger3.0 mods为空 HOT 1
- vs-code插件没有自动启动mock服务 HOT 1
- Java后端入参类型是List<Object>,生成的代码入参是Object,不识别List格式 HOT 1
- 无法设置rootDir
- "spiltApiLock": true, 执行pont scan 报错 找不到api.lock.json HOT 1
- "parameters" 原有的parameters数据,被覆盖,导致数据丢失 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pont.