How to use the vue-server-renderer/package.json.version function in vue-server-renderer

To help you get started, we’ve selected a few vue-server-renderer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Detachment / Build-vue-hackernews-2.0-from-scratch / tutorials / 2-Packages-Plugins-for-Better-User-Experience / server.js View on Github external
const fs = require('fs')
const path = require('path')
const express = require('express')
const favicon = require('serve-favicon')
const compression = require('compression')
const serialize = require('serialize-javascript')
const resolve = file => path.resolve(__dirname, file)

const isProd = process.env.NODE_ENV === 'production'
const serverInfo =
`express/${require('express/package.json').version}` +
`vue-server-renderer/${require('vue-server-renderer/package.json').version}`

const app = express()

let indexHTML  // generated by html-webpack-plugin
let renderer  // created from the webpack-generated server bundle
if(isProd){
    // in production: create server renderer and index HTML from real file
    renderer = createRenderer(fs.readFileSync(resolve('./dist/server-bundle.js'), 'utf-8'))
    indexHTML = parseIndex(fs.readFileSync(resolve('./dist/index.html'), 'utf-8'))
    console.log("In production mode now~");
}else {
    // in development: setup the dev server with watch and hot-reload,
    // and update renderer/index HTML on file change.
    require('./build/setup-dev-server')(app, {
        bundleUpdated: bundle => {
            renderer = createRenderer(bundle)
github asadsahi / vuenode-fullstack / server.js View on Github external
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const cors = require("cors");
const helmet = require("helmet");
const morgan = require("morgan");
const microcache = require("route-cache");
const resolve = file => path.resolve(__dirname, file);
const { createBundleRenderer } = require("vue-server-renderer");
const logger = require("./server/features/logger");
const isProd = process.env.NODE_ENV === "production";
const isDev = !isProd;
const ngrok = process.env.ENABLE_TUNNEL ? require("ngrok") : false;
const useMicroCache = process.env.MICRO_CACHE !== "false";
const serverInfo =
  `express/${require("express/package.json").version} ` +
  `vue-server-renderer/${require("vue-server-renderer/package.json").version}`;

global.appConfig = _.merge(
  {},
  require("./server/config.json"),
  require("./server/config.prod.json"),
  { isDev, isProd }
);
global.errorHandler = require("./server/features/core").errorHandler;

const app = express();
const db = require("./server/db/models");
const server = http.createServer(app);
const io = socketIO(server);

function createRenderer(bundle, options) {
  // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
github kazupon / vue-i18n / examples / ssr / hn2 / server.js View on Github external
const fs = require('fs')
const path = require('path')
const LRU = require('lru-cache')
const express = require('express')
const favicon = require('serve-favicon')
const compression = require('compression')
const microcache = require('route-cache')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')
const { directive } = require('vue-i18n-extensions')

const isProd = process.env.NODE_ENV === 'production'
const useMicroCache = process.env.MICRO_CACHE !== 'false'
const serverInfo =
  `express/${require('express/package.json').version} ` +
  `vue-server-renderer/${require('vue-server-renderer/package.json').version}`

const app = express()

const template = fs.readFileSync(resolve('./src/index.template.html'), 'utf-8')

function createRenderer (bundle, options) {
  // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
  return createBundleRenderer(bundle, Object.assign(options, {
    template,
    // for component caching
    cache: LRU({
      max: 1000,
      maxAge: 1000 * 60 * 15
    }),
    // this is only needed when vue-server-renderer is npm-linked
    basedir: resolve('./dist'),
github Goofies / Vue-Firebase-SSR-Template / server.js View on Github external
const fs = require('fs')
const path = require('path')
const LRU = require('lru-cache')
const express = require('express')
const favicon = require('serve-favicon')
const compression = require('compression')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')
const redirects = require('./router/301.json')

const isProd = process.env.NODE_ENV === 'production'
const useMicroCache = process.env.MICRO_CACHE !== 'false'
const serverInfo =
  `express/${require('express/package.json').version} ` +
  `vue-server-renderer/${require('vue-server-renderer/package.json').version}`

const app = express()

const template = fs.readFileSync(resolve('./assets/index.template.html'), 'utf-8')

function createRenderer (bundle, options) {
  // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
  return createBundleRenderer(bundle, Object.assign(options, {
    template,
    // for component caching
    cache: LRU({
      max: 1000,
      maxAge: 1000 * 60 * 15
    }),
    // this is only needed when vue-server-renderer is npm-linked
    basedir: resolve('./public'),
github Neveryu / vue-ssr-lessons / lesson4 / server.js View on Github external
const fs = require('fs')
const path = require('path')
const express = require('express')
const resolve = file => path.resolve(__dirname, file)
const { createBundleRenderer } = require('vue-server-renderer')

const isProd = process.env.NODE_ENV === 'production'

const serverInfo =
  `express/${require('express/package.json').version} ` + 
  `vue-server-renderer/${require('vue-server-renderer/package.json').version} `

const app = express()

function createRenderer(bundle, options) {
  return createBundleRenderer(bundle, Object.assign(options, {
    // this is only needed when vue-server-renderer is npm-linked
    basedir: resolve('./dist'),
    // recommended for performance
    runInNewContext: false
  }))
}

let renderer
let readyPromise
const templatePath = resolve('./src/index.template.html')
github zhangyuang / douBanByVueSsr / build / dev-server.js View on Github external
const fs = require('fs')
const path = require('path')
const LRU = require('lru-cache')
const express = require('express')
const compression = require('compression')
const isProd = process.env.NODE_ENV === 'production'
const serverInfo =
  `express/${require('express/package.json').version} ` +
  `vue-server-renderer/${require('vue-server-renderer/package.json').version}`
const app = express()
const { createBundleRenderer } = require('vue-server-renderer')
const template = require('fs').readFileSync(path.resolve('./src/template.html'), 'utf-8')
const serverBundle = require(path.resolve('./dist/vue-ssr-server-bundle.json'))
const clientManifest = require(path.resolve('./dist/vue-ssr-client-manifest.json'))
function resolve (dir) {
  return path.join(__dirname, dir)
}
let renderer
let readyPromise
function createRenderer (bundle, options) {
  return createBundleRenderer(bundle, Object.assign(options, {
    template,
    runInNewContext: false,
    // cache: LRU({
    //   max: 10000,
github Gingernaut / Peridot / server / server.js View on Github external
/* eslint-disable no-console */
const fs = require('fs')
const path = require('path')
const express = require('express')
const resolve = file => path.resolve(__dirname, file)
const LRU = require('lru-cache')
const injectToTemplate = require('./seo')
const { createBundleRenderer } = require('vue-server-renderer')
const config = require(resolve('../config/oracle'))
// const microcache = require('route-cache')
// const useMicroCache = config.useMicroCache
const templatePath = resolve('../src/index.template.html')

const serverInfo =
  `express/${require('express/package.json').version} ` +
  `vue-server-renderer/${require('vue-server-renderer/package.json').version}`

function createRenderer (bundle, options) {
  // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
  return createBundleRenderer(bundle, Object.assign(options, {
    // for component caching
    cache: LRU({
      max: 1000,
      maxAge: 1000 * 60 * 15
    }),
    // this is only needed when vue-server-renderer is npm-linked
    basedir: resolve('./dist'),
    // recommended for performance
    runInNewContext: false
  }))
}
github quasarframework / quasar / ui / build / script.dev.ssr.js View on Github external
path = require('path'),
  webpack = require('webpack'),
  LRU = require('lru-cache'),
  express = require('express'),
  { createBundleRenderer } = require('vue-server-renderer'),
  MFS = require('memory-fs'),
  chokidar = require('chokidar')

const
  clientConfig = require('./webpack.ssr.client'),
  serverConfig = require('./webpack.ssr.server'),
  env = require('./env'),
  resolve = file => path.resolve(__dirname, '..', file),
  serverInfo =
    `express/${require('express/package.json').version} ` +
    `vue-server-renderer/${require('vue-server-renderer/package.json').version}`,
  app = express(),
  templatePath = resolve('dev/ssr.index.html')

console.log()
console.log(` ☕️ Preparing for Quasar v${env.quasarVersion} on SSR`)
console.log()
console.log(` 🚀 Starting SSR dev server...`)
console.log(`    Will listen at ${env.displayURI}`)
console.log(`    Browser will open when build is ready.`)

const readFile = (fs, file) => {
  try {
    return fs.readFileSync(path.join(clientConfig.output.path, file), 'utf-8')
  }
  catch (e) {}
}
github TB-blog / TB / server.js View on Github external
const fs = require('fs');
const path = require('path');
const express = require('express');
const favicon = require('serve-favicon');
const compression = require('compression');
const microcache = require('route-cache');
const LRU = require('lru-cache');
const _config = require('./config.json');
const resolve = file => path.resolve(__dirname, file);
const { createBundleRenderer } = require('vue-server-renderer');

const isProd = process.env.NODE_ENV === 'production';
const useMicroCache = process.env.MICRO_CACHE !== 'false';
const serverInfo =
  `express/${require('express/package.json').version} ` +
  `vue-server-renderer/${require('vue-server-renderer/package.json').version}`;

const app = express();

function createRenderer (bundle, options) {
  return createBundleRenderer(bundle, Object.assign(options, {
    cache: LRU({
      max: 1000,
      maxAge: 1000 * 60 * 15
    }),
    basedir: resolve('./dist'),
    runInNewContext: false
  }));
}

let renderer;
let readyPromise;