Skip to content

Instantly share code, notes, and snippets.

View erasmo-marin's full-sized avatar

Erasmo Marín erasmo-marin

  • Chile
View GitHub Profile
@erasmo-marin
erasmo-marin / switch2.jsx
Last active August 27, 2017 13:25
Conditionally load a component 2
import React from "react";
import { Component1, Component2, Component3 } from "./file";
const Switch = ({ n, …rest }) => {
switch(n) {
case 1:
return <Component1 {...rest}/>;
case 2:
return <Component2 {...rest}/>;
case 3:
@erasmo-marin
erasmo-marin / switch.jsx
Last active August 25, 2017 14:00
Conditionally load a component 1
import React from "react";
import { Component1, Component2 } from "./file";
const Switch = ({ condition, …rest }) => (
<div>
{condition ? <Component1 {…rest}/> : <Component2 {…rest}/>}
</div>
)
var oneWeek = 86400000*7;
app.use(express.static(path.join(__dirname, "public"), { maxAge: oneWeek, lastModified: true }));
//this middleware serves all js files as gzip
app.use(function(req, res, next) {
var originalPath = req.path;
if(!originalPath.endsWith(".js")) {
next();
return;
}
try {
var stats = fs.statSync(path.join("public", `${req.path}.gz`));
res.append('Content-Encoding', 'gzip');
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
var compression = require('compression');
var app = express();
app.use(compression());
const determineDate = () => {
import('moment').then((moment) => {
console.log(moment().format());
}).catch((err) => {
console.log('Failed to load moment', err);
});
}
determineDate();
...
presets: [
["es2015", { loose: true, modules: false }],
"react"
]
...
...
presets: [
["es2015", { loose: true }],
"react"
]
...
plugins: [
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
mangle: true,
sourcemap: false,
debug: false,
minimize: true,
compress: {