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
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}]
]
}
import 'moment/locale/es';
import 'moment/locale/pt';
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
const Sidebar = dynamicComponent(() =>
import(/* webpackChunkName: "Sidebar" */ './components/sidebar')
);
import React, { Component } from 'react';
export default function dynamicComponent(importComponent) {
class DynamicComponent extends Component {
constructor(props) {
super(props);
this.state = {
component: null
};
async function fetchAllPages() {
const domain = "https://mycooleebsite.com";
const pages = [
"/",
"/about",
"/pricing",
"/contact"
]
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
import detector from "spider-detector";
import url from "url";
app.use(detector.middleware());
app.get("*", function(req, res, next) {
//we only serve static snapshots to spiders
if(!req.isSpider() ) {
next();
import puppeteer from "puppeteer";
async function crawler({ url }) {
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
let page = null;
let html = false;
try {
page = await browser.newPage();
import puppeteer from "puppeteer";
async function crawler({ url, browser }) {
let page = null;
let html = false;
try {
page = await browser.newPage();
//networkidle0: consider navigation to be finished when
//there are no more than 2 network connections for at least 500 ms.
import fsPath from "fs-path";
const saveUrlToFile = ({ html = "", pathName = "/", output = "." }) => {
const path = pathName == "/"
? `${output}/index.html`
: `${output}${pathName}.html`;
fsPath.writeFile(path, html, err => {
if (err) {