Code Monkey home page Code Monkey logo

reactnativepackagedemo's Introduction

React-Native 分包实践


对于很多在使用react-native开发应用的小伙伴们肯定都会遇到一个问题,功能越来越复杂,生成的jsbundle文件越来越大,无论是打包在app内发布还是走http请求更新bunlde文件都是噩梦,这个时候我们应该如何来更新呢?来看看我们的方案。

Bundler-->Reslover:getDependencies
Reslover-->DependencyResolver:
DependencyResolver-->Reslover:
Reslover-->Bundler:return system + Polyfill + dependencies
Bundler-->JSTransformer:loadFileAndTransform
JSTransformer-->Bundler:返回babel转换后的代码
note over Bundler:finalize

finalize会根据参数runMainModule在生成的代码插入执行代码,然后我们就能获得生成的bundle文件了

-- 通过上面的过程了解后,我们可以在原有的基础上进行扩展,在获取到denpendencies后(onResolutionResponse)通过请求参数,选择过滤基础模块或者仅基础模块,这时就能生成我们需要的文件。

//react-native/packager/react-packager/src/Bundler/index.js onResolutionResponse
if (withoutSource) {
    response.dependencies = response.dependencies.filter(module = >
    !~module.path.indexOf('react-native')
)
    ;
} else if (sourceOnly) {
    response.dependencies = response.dependencies.filter(module = >
    ~module.path.indexOf('react-native')
)

同时修改RCTbridge暴露enqueueApplicationScript接口来将加载后的source运行到javascript core

reactnativepackagedemo's People

Contributors

atrl avatar

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.