Taro: 增加打包到dist完成后可选的执行其他操作功能

Created on 15 Aug 2020  ·  2Comments  ·  Source: NervJS/taro

这个特性解决了什么问题?

使用windows wsl2开发时,项目创建在wsl的linux目录下,taro打包完成后字节小程序工具没法正确读取在dist目录下打包结果后预览效果(微信小程序工具也一样),自己动手加个监听脚本,rsync同步到windows下后的目录后用小程序在windows目录下预览才能正常开发

注意这个问题只对安装在wsl2下的taro,安装在windows下的taro正常.

这个 API 长什么样?

我是个windows wsl2用户 前端新人,刚接触taro(taro3) 1周,在windows(wsl2)下开发遇到windows下的小程序工具无法正确读取打包结果的问题,目前自己在根目录下新建了个 这样的watch-dist-and-sync.sh文件

#!/bin/sh

# windows端小程序工具无法正确读取dist目录,
# 监听打包完成后的app.json并同步打包结果到 windows文件目录下
#
## 需要inotify-tools 如果系统未安装执行下面命令安装
## $ sudo apt-get install inotify-tools
inotifywait -qm --event modify ./dist/app.json | \
    while read _; do
        rsync -aurv ./dist/* /mnt/your/path/in/windows/
    done

然后

  • 执行 taro build --type tt --watch
  • 执行 bash watch-dist-and-sync.sh

这么开发

希望能在 package.json里增加打包完成后可选的执行命令选项来省去手动挂起脚本

enhancement

Most helpful comment

@toknT 你可以尝试编写一个 Taro 插件,它可以调用 CLI 的 onBuildFinish 钩子

https://nervjs.github.io/taro/docs/next/plugin/#%E5%A6%82%E4%BD%95%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E6%8F%92%E4%BB%B6

All 2 comments

@toknT 你可以尝试编写一个 Taro 插件,它可以调用 CLI 的 onBuildFinish 钩子

https://nervjs.github.io/taro/docs/next/plugin/#%E5%A6%82%E4%BD%95%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E6%8F%92%E4%BB%B6

收到,等有空补习下nodejs然后写个插件. 目前先手动跑脚本或者用最近发现的vscode file watch 插件

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhuxianguo picture zhuxianguo  ·  3Comments

wyhaya picture wyhaya  ·  3Comments

rainbowMorelhahahah picture rainbowMorelhahahah  ·  3Comments

GreatAuk picture GreatAuk  ·  3Comments

liu-dongyu picture liu-dongyu  ·  3Comments