Skip to content

Instantly share code, notes, and snippets.

@bdwain
bdwain / Server.js
Last active December 26, 2016 05:47
Webpack dev server will not restart correctly
//I tried editing the webpack dev server prototype to use the middleware callback, but it had the same issue
//new version
Server.prototype.close = function(callback) {
this.sockets.forEach(function(sock) {
sock.close();
});
this.listeningApp.close(function() {
//this is only reached the first call to close
this.middleware.close(callback);
@bdwain
bdwain / Themes.js
Created December 31, 2016 10:34
Using Context and ShouldComponentUpdate
class ThemeProvider extends React.Component {
constructor(p, c) {
super(p, c)
this.getColor = this.getColor.bind(this)
}
getColor(){
return this.props.color //could be this.state.color
}
@bdwain
bdwain / uglifybug.js
Created May 17, 2017 22:55
this demonstrates the issue where the reduce_vars option for uglify causes a bug with the string.split prototype
This file has been truncated, but you can view the full file.
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@bdwain
bdwain / working.js
Created May 17, 2017 22:57
this copy of the app works because babel polyfill was removed
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@bdwain
bdwain / broken.js
Created May 17, 2017 23:06
this demonstrates the issue where the reduce_vars option for uglify causes a bug with the string.split prototype Raw
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@bdwain
bdwain / working.js
Created May 17, 2017 23:07
this copy of the app works because babel polyfill was removed Raw
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@bdwain
bdwain / rollup-exports.js
Last active October 25, 2017 05:36
Reorganize exports rollup plugin
const { parse } = require('acorn');
const MagicString = require('magic-string');
//this parses the returned source code and removes all functions from the main export {...};
//it then changes those functions from `function foo(){...}` to `export function foo(){...}`
//if any variables in any file are named the same as an exported function, this will error out.
//A full solution would need to be included as part of rollup. https://github.com/rollup/rollup/issues/1682
function plugin(){
return {