Code Monkey home page Code Monkey logo

webpack-prerender-spa-plugin's Introduction

Usage

webpack config

var path = require('path')
var PrerenderPlugin = require('webpack-prerender-spa-plugin')

module.exports = {
  // ...
  plugins: [
    new PrerenderPlugin({
      // (REQUIRED) Absolute path to static root
      dist: path.resolve(__dirname, '../dist'),

      // (REQUIRED) server entry
      entry: path.resolve(__dirname, '../index'),

      // (REQUIRED) server host
      host: 'http://127.0.0.1',

      // (REQUIRED) server port
      port: 7000,

      // (REQUIRED) List of routes to prerender
      routes: ['/login'],

      // (OPTIONAL) Options
      options: {
        // NOTE: Unless you are relying on asynchronously rendered content,
        // such as after an Ajax request, none of these options should be
        // necessary. All synchronous scripts are already executed before
        // capturing the page content.

        // Wait until a specific event is fired on the document.
        captureAfterDocumentEvent: 'custom-post-render-event',

        // This is how you would trigger this example event:
        // document.dispatchEvent(new Event('custom-post-render-event'))

        // Wait until a specific element is detected with
        // document.querySelector.
        captureAfterElementExists: '#content',

        // Wait until a number of milliseconds has passed after scripts
        // have been executed. It's important to note that this may
        // produce unreliable results when relying on network
        // communication or other operations with highly variable timing.
        captureAfterTime: 5000,

        // NOTE: You can even combine strategies if you like. For example,
        // if you only _sometimes_ want to wait for an event to fire, you
        // can create a timeout by combining captureAfterTime with
        // captureAfterDocumentEvent. When combining strategies, page
        // content will be captured after the first triggered strategy.

        // Because PhantomJS occasionally runs into an intermittent issue,
        // we will retry a page capture up to 5 times by default. You may
        // raise or lower this limit if you wish.
        maxAttempts: 10,

        // Prevent PhantomJS from navigating away from the URL passed to it
        // and prevent loading embedded iframes (e.g. Disqus and Soundcloud
        // embeds), which are not ideal for SEO and may introduce JS errors.
        navigationLocked: true,

        // The options below expose configuration options for PhantomJS,
        // for the rare case that you need special settings for specific
        // systems or applications.

        // http://phantomjs.org/api/command-line.html#command-line-options
        phantomOptions: '--disk-cache=true',

        // http://phantomjs.org/api/webpage/property/settings.html
        phantomPageSettings: {
          loadImages: true
        }
      }
    })
  ]
}

webpack-prerender-spa-plugin's People

Contributors

okoala avatar

Stargazers

Scott Powell avatar Sam Wray avatar Cuity avatar Paweł Borecki avatar Chris Braddock avatar Nico Müller avatar  avatar PHPS avatar wangZhuo avatar Ivan Demidov avatar Pavol Madar avatar newraina avatar hzuhyb avatar heyli avatar balibabu avatar  avatar xialvjun avatar JeeSoong avatar

Watchers

James Cloos avatar  avatar  avatar

webpack-prerender-spa-plugin's Issues

Error: stdout maxBuffer exceeded

Config

    new PrerenderPlugin({
      dist: path.resolve(__dirname, '../dist'),
      entry: path.resolve(__dirname, '../index.html'),
      host: 'http://localhost',
      port: 8887,
      routes: ['/'],
      options: {
        captureAfterTime: 5000,
        maxAttempts: 20,
        // http://phantomjs.org/api/command-line.html#command-line-options
        phantomOptions: '--disk-cache=true',
        // http://phantomjs.org/api/webpage/property/settings.html
        // phantomPageSettings: {
        //     loadImages: true
        // },
      }
    }),

After running my build, I'm getting this error:

node_modules/webpack-prerender-spa-plugin/lib/compile-to-html.js:31
              if (error) throw error
                         ^

Error: stdout maxBuffer exceeded
    at Socket.<anonymous> (child_process.js:259:14)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:548:20)
error Command failed with exit code 1.

How does this work?

Hello! Thank you for this plugin. It was the only only worked not giving me headaches.
What is the output after prerendering my spa? Should I see any new files somewhere?
Could you help me out explaining how does this work?

Thank you in advance

你好,有两个问题想请教

1:可以支持动态路由吗?类似'/shops/:id'
2:可以指定某些路由打包成静态页面,其他的路由还是原来打包不变吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.