Coder Social home page Coder Social logo

cache-manager's Introduction

cache-manager

用于针对构建产物进行缓存的工具。

想法

在构建环节,一般会有两种构建模式,分别是 bundle 和 bundless。虽然构建不是高频的任务,但是也会在一些环节影响开发的体验。因此为了提高构建时候所花费的时间,可能会想到通过缓存的方式来提高构建的速度。

通过缓存提高构建速度的原理是:通过检测变化来确认需要对哪部分执行构建任务,而对剩余的部分,则直接使用缓存

而速度的提升往往取决于检测变化的机制缓存单位大小

bundless 场景下的缓存

对于 bundless 的场景,很自然的想到以文件作为缓存单位进行缓存。当一个文件变化的时候,我们就仅仅对这个文件重新编译,输出并替换掉之前的文件。因此 bundless 的场景通过缓存提升构建速度是很容易的。但是这里其实还有些需要考量的东西,就是上面提到一点 —— 检测变化的机制

对于触发重新执行构建任务的时机,最简单的方式当然是比较两个文件是否相同。但是在一些情况下,我们可以更精准的判断“是否发生了变化”。

例如源文件是一个 '.js' 文件,如果仅仅增加了一个空格或者空行,按照上面检测文件内容是否发生变化的条件来判断,那么这个文件就要重新编译构建。然而从开发者的角度来看,对于 js 文件/模块来说增加了一个空格或者空行不会影响实际的功能和意义,因此没有必要重新进行编译处理,也就应该直接使用缓存来跳过构建过程。

bundle 场景下的缓存

目前社区里 bundler 有 webpack、rollup、parcel、esbuild ...。这里 webpack 和 rollup 大概算是使用老牌的以及用户量很大的 bundler 工具,它们在 Web 应用项目中用的是最多的(其中 webpack 应该是最多的)。

Web 应用的大小和复杂度随着时间、团队人员的增加,其源码的大小也是会变得越来越大,其每次构建时候所花费的时间,也是随着项目的大小,变的越来越长。因此对于 Web 应用项目通过缓存的方式来提高构建速度是有必要的。

在上面提到的 bundler 中,目前提供了缓存功能有 webpack、parcel。

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.