ABuffSeagull
7 years ago
commit
e07ffed0b7
4 changed files with 1301 additions and 0 deletions
@ -0,0 +1,80 @@ |
|||
|
|||
# Created by https://www.gitignore.io/api/node |
|||
|
|||
### Node ### |
|||
# Logs |
|||
logs |
|||
*.log |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
|
|||
# Runtime data |
|||
pids |
|||
*.pid |
|||
*.seed |
|||
*.pid.lock |
|||
|
|||
# Directory for instrumented libs generated by jscoverage/JSCover |
|||
lib-cov |
|||
|
|||
# Coverage directory used by tools like istanbul |
|||
coverage |
|||
|
|||
# nyc test coverage |
|||
.nyc_output |
|||
|
|||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) |
|||
.grunt |
|||
|
|||
# Bower dependency directory (https://bower.io/) |
|||
bower_components |
|||
|
|||
# node-waf configuration |
|||
.lock-wscript |
|||
|
|||
# Compiled binary addons (https://nodejs.org/api/addons.html) |
|||
build/Release |
|||
|
|||
# Dependency directories |
|||
node_modules/ |
|||
jspm_packages/ |
|||
|
|||
# TypeScript v1 declaration files |
|||
typings/ |
|||
|
|||
# Optional npm cache directory |
|||
.npm |
|||
|
|||
# Optional eslint cache |
|||
.eslintcache |
|||
|
|||
# Optional REPL history |
|||
.node_repl_history |
|||
|
|||
# Output of 'npm pack' |
|||
*.tgz |
|||
|
|||
# Yarn Integrity file |
|||
.yarn-integrity |
|||
|
|||
# dotenv environment variables file |
|||
.env |
|||
|
|||
# parcel-bundler cache (https://parceljs.org/) |
|||
.cache |
|||
|
|||
# next.js build output |
|||
.next |
|||
|
|||
# nuxt.js build output |
|||
.nuxt |
|||
|
|||
# vuepress build output |
|||
.vuepress/dist |
|||
|
|||
# Serverless directories |
|||
.serverless |
|||
|
|||
|
|||
# End of https://www.gitignore.io/api/node |
@ -0,0 +1,40 @@ |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const mkdirp = require('mkdirp'); |
|||
const chalk = require('chalk'); |
|||
const Prerenderer = require('@prerenderer/prerenderer'); |
|||
const Puppeteer = require('@prerenderer/renderer-puppeteer'); |
|||
|
|||
module.exports = bundler => { |
|||
const { outDir } = bundler.options; |
|||
const prerenderer = new Prerenderer({ |
|||
staticDir: outDir, |
|||
renderer: new Puppeteer(), |
|||
}); |
|||
bundler.on('buildEnd', async () => { |
|||
if (process.env.NODE_ENV !== 'production') return; |
|||
console.log(chalk.bold('\nRendering...')); |
|||
try { |
|||
await prerenderer.initialize() |
|||
const start = new Date().getTime(); |
|||
const renderedRoutes = await prerenderer.renderRoutes(['/', '/test']); |
|||
const end = new Date().getTime(); |
|||
renderedRoutes.forEach(route => { |
|||
try { |
|||
const outputDir = path.join(outDir, route.route); |
|||
const file = path.normalize(`${outputDir}/index.html`); |
|||
mkdirp.sync(outputDir); |
|||
fs.writeFileSync(file, route.html.trim()); |
|||
const end = new Date().getTime(); |
|||
} catch (err) { |
|||
console.error(err); |
|||
} |
|||
}); |
|||
console.log(`Finished rendering in ${end - start}ms.`); |
|||
prerenderer.destroy(); |
|||
} catch (err) { |
|||
prerenderer.destroy(); |
|||
console.error(err); |
|||
} |
|||
}); |
|||
} |
@ -0,0 +1,14 @@ |
|||
{ |
|||
"name": "parcel-plugin-prerender", |
|||
"version": "1.0.0", |
|||
"main": "index.js", |
|||
"license": "MIT", |
|||
"private": true, |
|||
"devDependencies": {}, |
|||
"dependencies": { |
|||
"@prerenderer/prerenderer": "^0.7.1", |
|||
"@prerenderer/renderer-puppeteer": "^0.1.4", |
|||
"chalk": "^2.4.1", |
|||
"mkdirp": "^0.5.1" |
|||
} |
|||
} |
File diff suppressed because it is too large
Loading…
Reference in new issue