How to tell webpack dev server to serve index.html for any route

React router allows react apps to handle /arbitrary/route. In order this to work, I need my server to send the React app on any matched route. But webpack dev server doesn’t handle arbitrary end points. There is a solution here using additional express server. How to allow for webpack-dev-server to allow entry points from react-router … Read more

Enums in Javascript with ES6

I’m rebuilding an old Java project in Javascript, and realized that there’s no good way to do enums in JS. The best I can come up with is: const Colors = { RED: Symbol(“red”), BLUE: Symbol(“blue”), GREEN: Symbol(“green”) }; Object.freeze(Colors); The const keeps Colors from being reassigned, and freezing it prevents mutating the keys and … Read more

“unexpected token import” in Nodejs5 and babel?

In js file, i used import to instead of require import co from ‘co’; And tried to run it directly by nodejs since it said import is ‘shipping features’ and support without any runtime flag (, but i got an error import co from ‘co’; ^^^^^^ SyntaxError: Unexpected token import Then i tried to use … Read more

React functional stateless component, PureComponent, Component; what are the differences and when should we use what?

Came to know that from React v15.3.0, we have a new base class called PureComponent to extend with PureRenderMixin built-in. What I understand is that, under the hood this employs a shallow comparison of props inside shouldComponentUpdate. Now we have 3 ways to define a React component: Functional stateless component which doesn’t extend any class … Read more

Null-safe property access (and conditional assignment) in ES6/2015

Is there a null-safe property access (null propagation / existence) operator in ES6 (ES2015/ like ?. in CoffeeScript for example? Or is it planned for ES7? var aThing = getSomething() … aThing = possiblyNull?.thing This will be roughly like: if (possiblyNull != null) aThing = possiblyNull.thing Ideally the solution should not assign (even undefined) to … Read more

Export multiple classes in ES6 modules

I’m trying to create a module that exports multiple ES6 classes. Let’s say I have the following directory structure: my/ └── module/ ├── Foo.js ├── Bar.js └── index.js Foo.js and Bar.js each export a default ES6 class: // Foo.js export default class Foo { // class definition } // Bar.js export default class Bar { … Read more