Skip to content

Instantly share code, notes, and snippets.

View jpvincent's full-sized avatar

Jean-Pierre Vincent jpvincent

View GitHub Profile
@gilmoreorless
gilmoreorless / README.md
Last active January 21, 2019 22:14
Webpack helper for moment-timezone data

This is outdated!

The content of this gist has been superseded by a new proper plugin for webpack: https://github.com/gilmoreorless/moment-timezone-data-webpack-plugin

The original contents of the gist are kept below for context, but I encourage people to use the plugin instead.


This is a custom helper script I wrote for a project’s Webpack build. It reduces the amount of time zone definition data loaded by moment-timezone. This helps reduce the size of the JS bundle loaded in a browser.

"use strict";
const Mustache = require("mustache");
const path = require("path");
/**
* This plugin is used to generate an html file from a mustache template.
* @param {object} options
* - enabled {boolean} whether plugin is enabled
* - outputFile {string} the relative path to the html file result
@jpvincent
jpvincent / optimizedFor.js
Last active November 25, 2021 17:12
never blocking loop mechanism, using setTimeout 0 trick and time control to break the loop and let the browser breath
/**
* NEVER BLOCKING LOOP : implementation of the infamous setTimeout 0 hack, with time checking in order to guarantee fluidity without sacrificing execution speed.
*
* USAGE :
* var array = ["a way too big array that is heavy to process"]
* optimizeFor({
* nbIterations: array.length,
* each:function( index ) {
* doSomethingUsefulWith( array[ index ] );
* },