惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
S
Security @ Cisco Blogs
宝玉的分享
宝玉的分享
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Latest news
Latest news
NISL@THU
NISL@THU
S
Security Affairs
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 聂微东
AI
AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
小众软件
小众软件
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
AWS News Blog
AWS News Blog
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
I
InfoQ
Schneier on Security
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
IT之家
IT之家
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
腾讯CDC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
H
Heimdal Security Blog
S
SegmentFault 最新的问题

oida.dev | TypeScript, Rust

TypeScript's `erasableSyntaxOnly` Flag Unsafe for work Tokio: Macros Tokio: Channels Tokio: Getting Started Network Applications on the Tokio Stack Remake, Remodel, Reduce. The `never` type and error handling in TypeScript 5 Inconvenient Truths about TypeScript Refactoring in Rust: Introducing Traits Refactoring in Rust: Abstraction with the Newtype Pattern Announcing the TypeScript Cookbook TypeScript: Iterating over objects The road to universal JavaScript 10 years of oida.dev Rust: Tiny little traits The TypeScript converging point How not to learn TypeScript Getting started with Rust Introducing Slides and Coverage TypeScript: The humble function overload TypeScript + React: Children types are broken TypeScript: In defense of any Rust: Enums to wrap multiple errors Dissecting Deno Error handling in Rust TypeScript: Unexpected intersections Upgrading Node.js dependencies after a yarn audit TypeScript: Array.includes on narrow types TypeScript + React: Typing Generic forwardRefs shared, util, core: Schroedinger's module names Learning Rust and Go TypeScript: Narrow types in catch clauses TypeScript: Low maintenance types Tidy TypeScript: Name your generics Tidy TypeScript: Avoid traditional OOP patterns Tidy TypeScript: Prefer type aliases over interfaces Tidy TypeScript: Prefer union types over enums My new book: TypeScript in 50 Lessons Go Preact! ❤️ this in JavaScript and TypeScript TypeScript and ECMAScript Modules TypeScript + React: Why I don't use React.FC TypeScript + React: Component patterns TypeScript: Augmenting global and lib.dom.d.ts Vite with Preact and TypeScript TypeScript: Union to intersection type 11ty: Generate Twitter cards automatically Are large node module dependencies an issue? TypeScript: Variadic Tuple Types Preview TypeScript: Improving Object.keys Remake, Remodel. Part 4. TypeScript + React: Typing custom hooks with tuple types TypeScript: Assertion signatures and Object.defineProperty TypeScript: Check for object properties and narrow down type Boolean in JavaScript and TypeScript void in JavaScript and TypeScript Symbols in JavaScript and TypeScript Why I use TypeScript TypeScript + React: Extending JSX Elements TypeScript: Validate mapped types and const context TypeScript: Match the exact object shape TypeScript: The constructor interface pattern Streaming your Meetup - Part 4: Directing and Streaming with OBS Streaming your Meetup - Part 3: Speaker audio Streaming your Meetup - Part 2: Speaker video Streaming your Meetup - Part 1: Basics and Projector TypeScript and React Guide: Added a new styles chapter TypeScript and React Guide: Added a new render props chapter TypeScript and React: Styles and CSS TypeScript and React TypeScript and React Guide: Added a new prop types chapter TypeScript without TypeScript -- JSDoc superpowers TypeScript: Mapped types for type maps JAMStack vs serverless web apps The Unsung Benefits of JAMStack Sites TypeScript: Ambient modules for Webpack loaders My most favourite talks in 2018 TypeScript and React Guide: Added a new context chapter TypeScript: Built-in generic types TypeScript: Type predicates JSX is syntactic sugar TypeScript and React Guide: Added a new hooks chapter Getting your CfP application right FAQ on our Angular Connect Talk: Automating UI development TypeScript and Substitutability Debugging Node.js apps in TypeScript with Visual Studio Code From Medium: Deconfusing Pre- and Post-processing From Medium: PostCSS misconceptions Saving and scraping a website with Puppeteer Cutting the mustard - 2018 edition Wordpress as CMS for your JAMStack sites My most favourite podcast episodes in 2017 My most favourite talks in 2017 My most favourite books in 2017 The Best Request Is No Request, Revisited Not so hidden figures - Organizing ScriptConf My podcast journey to ScriptCast Grid layout, grid layout everywhere! #scriptconf and #devone
Gulp 4: Incremental builds with gulp.lastRun
2015-09-09 · via oida.dev | TypeScript, Rust

Incremental builds are a good way of speeding up your build iterations. Instead of building everything again with each and every iteration, you just process the files that have changed.

The Gulp 3 way #

Gulp has plenty of plugins for crafting incremental build pipelines. Some of the most common used are gulp-cached:

/** Gulp 3 Code **/

var cached = require('gulp-cached');
var jshint = require('gulp-jshint');

gulp.task('jshint', function() {
return gulp.src('scripts/**/*.js')
.pipe(cached('scripts')) /** 1 **/
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});

gulp.watch('scripts/**/*.js', ['jshint'])

  1. This line installs a build cache for incremental builds. With each iteration, Gulp checks if the files have been updated. If not, they will be filtered, resulting in a slimmer stream. gulp-cached will check both timestamp and contents.

While this appraoch delivers great results, they all have some caveat: With gulp.src all files are read. Which means that you have to transfer all the contents into memory. This can be optimized with Gulp 4.

The Gulp 4 way #

The virtual file sytem in Gulp 4 adds a new flag when globbing files through gulp.src. The since option. This option takes a timestamp, and gulp.src will filter files that are older than the given time. This alone is powerful enough, but it really shines when being combined with the lastRun function from the task manager.

With version 4, Gulp saves the time when a task has been executed last. Not only for the whole system, but also for each task separately. We can combine those two features by telling Gulp to “select files since” “the last time task X ran”:

/** Gulp 4 Code **/

var jshint = require('gulp-jshint');

gulp.task('jshint', function() {
return gulp.src('scripts/**/*.js', { since: gulp.lastRun('jshint') })
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});

gulp.watch('scripts/**/*.js', gulp.parallel('jshint'))

The biggest advantage here: The files don’t even get selected, which reduces reading operations with every iteration.

Where you still need some plugins #

You will still need plugins when you terminate Gulp between your iterations, since Gulp loses all information on runs once it exits. gulp-newer comes in handy:

/** Gulp 3 Code **/
var newer = require('gulp-newer');
var imagemin = require('gulp-imagemin');

gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe(newer('dist')) /** 1 **/
.pipe(imagemin())
.pipe(gulp.dest('dist'));
});

  1. Here we use gulp-newer to check if any of the images in our source stream have a newer timestamp than their results in the dist folder. gulp-newer just checks for newer timestamps and ignores contents. Compared to gulp-cached it can be used in multiple Gulp runs, not needing a watcher.

You also need the cached plugin if you want to refill your stream with original contents through gulp-remember afterwards. However, this can be combined with lastRun:

gulp.task('scripts', function() {
return gulp.src('src/**/*.js', since: {gulp.lastRun('scripts')}) /** 1 **/
.pipe(cached('scripts')) /** 2 **/
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.pipe(uglify())
.pipe(remember('scripts')) /** 3 **/
.pipe(concat('main.min.js'))
.pipe(gulp.dest('dest'));
});
  1. We select all files that have changed since the last run of this task. Which means that for the first run, this contains all files.
  2. We store those files in our cache. We will need them later. In the second run, this actually does filter nothing
  3. After our heavy tasks, we restore files from our cache so we can concatenate them.

This is actually the same as we would’ve done with Gulp 4, but we save lots of file reading operations with each iteration.

Related Articles