V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tomoya92
V2EX  ›  问与答

weex 有像 react native 一样的改代码模拟器立即生效的功能吗?

  •  
  •   tomoya92 · 2017-12-22 09:30:03 +08:00 · 2540 次点击
    这是一个创建于 2310 天前的主题,其中的信息可能已经有所发展或是发生改变。

    之前用 react native 开发都是一次运行一直到开发好,只要改了代码,在模拟器上 command + r 就更新了视图,相当方便

    现在入门 weex,死活找不到这方面的功能,难道没有?但网上找了一篇博客,上面说有这功能,然后就没有下文了

    11 条回复    2018-03-21 22:28:04 +08:00
    freeminder
        1
    freeminder  
       2017-12-22 10:03:50 +08:00
    额,可以把 weex 的加载写成来自 http 的,pc 上面随便弄一个 server 服务起来编译好的 bundle,不是很简单吗?这句话说的就是这个意思呀
    tomoya92
        2
    tomoya92  
    OP
       2017-12-22 10:14:34 +08:00
    @freeminder #1 weex 没找到在哪设置这个地址。。
    freeminder
        3
    freeminder  
       2017-12-22 10:20:45 +08:00
    @liygheart 你运行 weex 的 native 壳用的是自己编译的还是 playground?
    tomoya92
        4
    tomoya92  
    OP
       2017-12-22 10:22:58 +08:00
    @freeminder #3 用命令 `weex platform add ios` 加的
    freeminder
        5
    freeminder  
       2017-12-22 10:29:26 +08:00
    @liygheart 没怼过 ios,我编的 android。可以去 weex 官方文档里面看看加载远程 bundle 的部分,把本地 ios 工程的代码照抄改一下。如果觉得弄不聊这个,就直接用 playground 扫码吧。weex debug 开启一个 web debug server
    tomoya92
        6
    tomoya92  
    OP
       2017-12-22 10:48:21 +08:00
    @freeminder #5 嗯,我再折腾一下
    freeminder
        7
    freeminder  
       2017-12-22 10:59:01 +08:00
    @liygheart 哦对了,记得发送一下抖动指令给设备,可能弹出 debug 菜单,我恍惚记得 android 是可以的。
    TakWolf
        8
    TakWolf  
       2017-12-22 11:11:30 +08:00
    我没用官方壳子,是手工集成的,想办法让下面两句重新调用,貌似就可以重新初始化页面:

    ```
    wxsdkInstance.renderByUrl(TAG, "http://192.168.99.187:8080/dist/index.js", null, null, WXRenderStrategy.APPEND_ASYNC);
    ```

    ```
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"js"];
    [_instance renderWithURL:url options:@{@"bundleUrl":[self.url absoluteString]} data:nil];
    ```
    tomoya92
        9
    tomoya92  
    OP
       2017-12-22 11:15:06 +08:00
    @TakWolf #8 嗯,我试试,谢谢

    @freeminder 谢谢
    tomoya92
        10
    tomoya92  
    OP
       2017-12-22 15:56:00 +08:00
    @TakWolf
    @freeminder

    折腾出了个办法,添加 platform 方式用的是 `weex platform add ios`

    然后找到 ios 里的 `config.xml` 把里面的 `<preference name="launch_locally" value="false" />`改成 false 这样 ios 里的 js 文件就会从网络获取

    启动 weex 服务 `npm run serve` 端口必须要是 8080,如果不是的可以在创建的 weex 项目里的 `webpack.dev.js` 里修改,启动后访问一下 `http://localhost:8080/dist/index.js` 能否访问通

    可以的话,就可以用 xcode 打开项目点击运行

    修改代码,模拟器更新操作:在模拟器里双击 home 键,把运行的 weex 程序退出后台,然后再打开,js 就会重新下载,然后视图就更新了,还是不优雅,不过比重新运行 `weex run ios` 快些

    ios 部分下载 js 代码在 `WeexBundleUrlLoder.m` 文件里面
    redcat
        11
    redcat  
       2018-03-21 22:28:04 +08:00
    有没有同学想玩 weex 的,我们这里阿里大牛已到位,收 weex 感兴趣的前端-安卓-iOS 的同学,简历:[email protected] 坐标杭州西溪
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2988 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:10 · PVG 19:10 · LAX 04:10 · JFK 07:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.