Code Monkey home page Code Monkey logo

wean's Introduction

wean logo

Build Status


🔥 Note this is early experimental! 实验阶段的主要工作是想办法让整体架构变稳定、简洁,不建议上生产。


wean 是一个小程序编译器前端,它负责将标准的微信小程序打包成 fre 代码,这样做有很多好处——

  • 小程序引擎 - 将打包产物跑到 APP webview 上,就可以成为专属小程序,如“携程小程序”
  • 开箱即用 - 更现代的标准,更短的开发链路,从某种程度上缓解微信小程序的历史包袱
  • 跨端 - 以保住微信为前提,一套代码,支持所有小程序端

wean 生成 fre 代码,借助 esbuild 做 js 的打包

QQ group

wean logo

Demo

Run

$ npm install
$ npm link
$ wean

Motivation

在 wean 之前,大量小程序工具使用 babel + webpack 进行打包,各种 loader 、plugin 导致整个开发链路变长,O(n^n) 一遍又一遍的 ast 遍历,复杂度指数级增长,编译耗时超级长,调试也超级困难

wean 旨在解决链路问题,它自研编译器和打包器,整体复杂度维持在 O(n),没有任何 AST 操作,同一个小程序项目,wean 大约比 taro(+webpack)快一百倍

Package

Package Description Version
wean 微信小程序打包器 npm
wean/wxml wxml 编译器 npm

Design

wean

License

MIT @ctripcorp

wean's People

Contributors

anyexinglu avatar changchangge avatar chuifengji avatar imtaotao avatar liulinboyi avatar lvbaiying avatar lzm0x219 avatar quarkgluonplasma avatar suchangv avatar timetravelcyn avatar winesu avatar yisar avatar zhongmeizhi avatar zhukunpenglinyutong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wean's Issues

npm init wepack可以正常拉取么?

会报错!!!

npm ERR! could not determine executable to run

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\devserve\AppData\Local\npm-cache_logs\2021-03-15T10_24_35_050Z-debug.log

重构 js asset

before:
当前阶段,我们对 js asset 的处理是,先作用域提升,然后分析 export import,再进行tree shaking

import {a} from 'a.js'
// a()

如果一个方法被导入了,但它没有被调用,则现在的 wean 无法 tree shaking 掉
https://medium.com/webpack/better-tree-shaking-with-deep-scope-analysis-a0b788c0ce77
解决方案就是,分析 js 文件的作用域,以及引用,这样可以做到 module 级别的 tree shaking

after:
使用 rollup 的思路,1. 构建 module graph,2. 构建 scope chain 3. 后置导入
这个思路除了可以做到更好的 tree shaking,还可以让架构变稳定

因为在构建 module graph 的时候,我们将一棵子树变成一个图,虽然都是 O(n),但树的遍历远不如一个 for 循环

另外,类似的思路,我们也许会重构 wxml asset,构建 wxml 的 module graph,以便更好地处理 template 和 slot 的 case

数据结构:

app.json
 - Page [
   - page1.js [
     - module1 [a b c]
       - module2 [d e f]
   ], 
   - page1.wxml
    ]
 - Page [page1.js, page2.wxml]

css隔离

打包后,子组件的样式会影响到父组件,目前没有做一个很好的css隔离。

zsh: command not found: wean

图虫小程序 @ 飘香豆腐 demo clone到本地
cd到demo根目录下依次执行命令
$ yarn add wean
$ npm install
$ npm link
$ wean -e app.json -o /dist/

执行最后一行命令时,显示zsh: command not found: wean。

umd 支持

umd 文件,通常是一个闭包函数,然后执行完了,就可以挂到 window 上了

那么问题来了……wean 应该怎么打包呢呜呜呜

删除掉 sdk

fre,berial,goober 都通过 cdn 的方式引入

是否有对wx:else做处理

wx:else 会 编译为 directs.$else(() => ,
看了下好像是通过 const [name, value] = node.directives[i] 获取条件, else 得到的是 [ 'wx:else', '' ],没有和 if 做联动么?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.