This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"presets": [ | |
["env", { | |
"targets": { | |
"browsers": ["last 2 versions", "safari >= 7"] | |
} | |
}] | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'moment/locale/es'; | |
import 'moment/locale/pt'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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$/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Sidebar = dynamicComponent(() => | |
import(/* webpackChunkName: "Sidebar" */ './components/sidebar') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
export default function dynamicComponent(importComponent) { | |
class DynamicComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
component: null | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchAllPages() { | |
const domain = "https://mycooleebsite.com"; | |
const pages = [ | |
"/", | |
"/about", | |
"/pricing", | |
"/contact" | |
] | |
const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
NewerOlder