Skip to content

Instantly share code, notes, and snippets.

@chrishalebarnes
chrishalebarnes / build.js
Created January 8, 2020 19:19
Browerify Example with Treeshaking and a Split Vendor Bundle
const browserify = require('browserify');
const fs = require('fs');
const hbsfy = require("hbsfy");
const treeshake = require('common-shakeify')
const factor = require('factor-bundle');
const path = require('path');
browserify({
entries: [ path.resolve('app/main.js'), path.resolve('app/another-entry.js') ],
paths: [ './node_modules','./app' ],
function deepFreeze(obj) {
return Object.entries(obj).reduce((result, [name, value]) => {
Object.freeze(result);
result[name] = value && value !== null && typeof value === 'object' ? deepFreeze(value) : value;
return result;
}, obj);
}
@chrishalebarnes
chrishalebarnes / qs.js
Created September 7, 2017 19:13
Safer QuerySelector
function qs(selector, callback, context) {
if(callback === undefined) return;
context = context || document;
const result = context.querySelector(selector);
if(result) {
return callback(result);
}
}
qs('.some .selector', (safeElement) => {
rm -rf node_modules/ && rm -rf bower_components/;
npm cache clean && bower cache clean;
npm install && bower install;