Coder Social home page Coder Social logo

Comments (8)

SolarLiner avatar SolarLiner commented on June 20, 2024 1

I'll add the ability to specify a file to run during post-processing in the configuration. It will execute the default export of that file.

from vue-cli-plugin-prerender-spa.

SolarLiner avatar SolarLiner commented on June 20, 2024

I am a bit against exposing the complete configuration to the file as it would effectively defeat the purpose of having a Vue CLI plugin in the first place, and introduce a lot of edge use cases that I'm not going to offer support for.

Regarding your particular use-case of cleaning HTML of mutated DOM outside of Vue, you could mitigate the behavior two ways:

  • Check in your code to see if pre-rendering or if being live. The plugin injects the __PRERENDER_INJECTED property into window when pre-rendering. By checking its existence you can prevent those scripts from running when pre-rendering.
  • If you have write access to those scripts, prevent the duplication by first checking for the DOM elements before adding them. This is actually preferred as the scripts will also fail elsewhere than when pre-rendering, as there might be other cases where they will be loaded a second time.

Another option would be to provide a collection of post-processing functions to run on demand. But that would most likely increase the number of options and I am not in favor of that.

The last resort option would be a sort of "mega post-processing" function that automatically runs cleanup procedures when detecting issues with the HTML - but I don't know how feasible that would be.

from vue-cli-plugin-prerender-spa.

zheeeng avatar zheeeng commented on June 20, 2024

@SolarLiner I tried to add conditions on judging execute async scripts by detecting window['__PRERENDER_INJECTED'], but fails. After reading the implementation of vue-cli-plugin-rerender-spa I found that the inject option and injectProperty doesn't pass down to rerender-spa-plugin.

Can we add more pass-down options in .prerender-spa.json?

from vue-cli-plugin-prerender-spa.

SolarLiner avatar SolarLiner commented on June 20, 2024

The prerender-spa-plugin does inject the object already by default. Furthermore, there's a custom object that is merged with the CLI plugin configuration and then passed to the renderer. In the configuration file, it's the "customRendererConfig" option.

I do realize now that you need the ìnjectobject if you actually want the plugin to inject the property intowindow`. I'll go provide a default one, but it's already configurable in the current state of things.

from vue-cli-plugin-prerender-spa.

zheeeng avatar zheeeng commented on June 20, 2024

Thx for your replying, I missed the customRendererConfig option. I get works done.

I just read a post: https://markus.oberlehner.net/blog/how-to-pre-render-vue-powered-websites-with-webpack/. I found that postProcess feature of prerender-spa-plugin would be useful in some cases. For instance, adding defer to script tag.

At present .prerender-spa.json only support json format, we can't use fuction type customRendererConfig. May we consider adding another valid config file .prerender-sparc?

from vue-cli-plugin-prerender-spa.

jamiecarter7 avatar jamiecarter7 commented on June 20, 2024

Took me a while to work out how to use this.

Might be worth adding something to the instructions page.

For those looking to inject a value into the renderer I did it as follows:
*inside your prerenderSpa: {}

customRendererConfig: {
  injectProperty: "__PRERENDER_INJECTED",
  inject: {
    test: "hi"
  }
},

data can be found at window.__PRERENDER_INJECTED
The above data would be window.__PRERENDER_INJECTED.test > "hi"

from vue-cli-plugin-prerender-spa.

SolarLiner avatar SolarLiner commented on June 20, 2024

The docs do say that customRendererConfig is passed to the renderer, so the Prerender Spa Plugins docs should be followed.

I can however still add something in the README.

from vue-cli-plugin-prerender-spa.

bigsee avatar bigsee commented on June 20, 2024

@SolarLiner thank you for the work to add the postProcess option - super helpful, as is the plugin in general! 😀

from vue-cli-plugin-prerender-spa.

Related Issues (20)

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.