Comments (8)
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.
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 intowindow
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.
@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.
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 into
window`. I'll go provide a default one, but it's already configurable in the current state of things.
from vue-cli-plugin-prerender-spa.
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.
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.
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.
@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)
- Meta information HOT 1
- Not working with vue cli 4.4 HOT 2
- Does it support with the route has params?
- Missing index.html when redirecting routes with vi18n HOT 2
- failed to launch chrome in heroku
- Missing the index.html and built dir is not correct too HOT 1
- FreeBSD Compatibility HOT 1
- index.html scripts get called twice
- How to remove the module HOT 4
- Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('html').use(<Plugin>) first. HOT 6
- Prerender for router with webhash history mode
- How do you handle styles?
- @click events not firing when built for production HOT 3
- Meta Information HOT 2
- CI/CD Error: EACCES: permission denied, rmdir '/my-project/dist'
- e2e tests fail with latest vue-cli + vue-prerender-spa-plugin HOT 1
- Cannot set property 'execStart' of undefined
- Add server configuration options HOT 1
- Not triggered on different env? HOT 4
- Can't Submit form alway reloading when button click
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-cli-plugin-prerender-spa.