Tencent / hel

A module federation SDK which is unrelated to tool chain for module consumer. 工具链无关的运行时模块联邦sdk.
https://tencent.github.io/hel/
Other
933 stars 79 forks source link

本地运行React-ts模版 #14

Closed lzs246 closed 1 year ago

lzs246 commented 1 year ago

仓库:https://github.com/hel-eco/hel-tpl-remote-react-comp-ts

背景

拉模板代码,本地yarn start,好像是提供不了本地remote服务(如果我错了,麻烦纠正)

我看了一下,yarn start,是跑的script/start.js,但是这个脚本里面就起了一个webpackDevServer,不具备生成hel-json的能力。

我试了一下,写个webpack插件,调用helDevUtils.extractHelMetaJson来生成hel-json,但是发现webpackDevServer中的文件是保存在内充中,没有文件实体,导致要修改太多。

我想请问下如果想让模版,拥有本地调试hel-micro中remote的能力(yarn start),请问有啥办法

望大佬指点

lzs246 commented 1 year ago

好像也能做,通过html-webpack-plugin中beforeEmit阶段,也能拿到html内容,从而解析出hel-json

fantasticsoul commented 1 year ago

目前有两种方式调试本地 react组件

1 ,基于 web-dev-server 调试 npm run start启动起来,然后另一个项目直接指定 custom.host 为启起来的这个域名与端口,例如http://localhost:3001,但这时可能会有样式丢失。

如遇到样式丢失,可自己追加样式

preFetchLib('xxx', {  
  custom:{  
      host: 'http://localhost:3001',
      extraCssList: [ 'www.xxx.com/<yousr_css_file.css>' ],
   }
})

2,基于构建产物调试(推荐) 执行以下3步即可:

之后另一个项目直接指定 custom.host 为http-server启起来的这个域名与端口即可。

fantasticsoul commented 1 year ago

文档里缺失了模块调试相关部分,周末我补上😭