Open Kjir opened 5 years ago
I had to create this issue "manually" since using the tool I get 414 Request-URI Too Large
😭
There should be a feature request
label, which I can't add myself apparently....
More than how to configure SSR entrance
any news on this one ? In my use case, I'm trying to set the runInNewContext
from the vue.config.js, without having to create 2 webpack build files.
What problem does this feature solve?
The guide for Server-Side rendering creates 2 webpack builds, one for the client and one for the server. Then you create a file that imports the outputs from those 2 builds and returns the responses to whatever framework you use (e.g. express). Let's call this file the server handler. The issue with this approach is that you would need a third webpack build to process the server handler through webpack as well. You might want to do that for a few different reasons:
What does the proposed API look like?
I can think of a few possible solutions:
1. Define the name of the server handler to emit
There could be a configuration option for
VueSSRServerPlugin
that defines one additional entry to emit in the Webpack configuration. This would mean that there could be at most 2 entries, one is used for creating the JSON bundle, the other one to emit the server handlerThe handler would look something like this:
The upside of this approach is that it should be relatively easy to accomplish this. Another upside is that this would be backwards compatible. The downside is that there would be quite a bit of configuration necessary to make it look nice — to avoid importing build outputs directly in code, which would add a dependency on our webpack configuration in the code.
2. Provide an alias that resolves to the renderer instead of emitting a JSON bundle
Another possible approach would be to change completely the way the VueSSRServerPlugin works to reduce the additional webpack configuration necessary. Here's how the webpack configuration would look like:
And here is how the server handler would look like:
The clear upside is the reduction of the boilerplate. The first big downside is that this would not be backwards compatible. It could be implemented as a new, different plugin. The second downside is that there might be other use cases I haven't considered.
createBundleRenderer
takes other arguments as well, and you might not want to instantiate it at the top level. A smaller downside is that some pieces are connected in webpack rather than in the code, making it unclear where the template is referenced from.3. Use a loader to transform the server entry
This would be similar to the first proposal, but it would change the way
createBundleRenderer
works.Starting from the server handler this time, here is how the usage would look like:
And the webpack configuration would be something like this:
This approach would have the upside of not requiring magic to happen on the webpack entries, making it possible to have multiple entrypoints. The second upside would be to just configure a loader where appropriate, instead of adding a plugin. The first downside is that we still have to include the client manifest from the build. The second downside is that is could not be feasible with a webpack loader.
So which one?
I believe this problem needs a deeper reflection on the implications for all possible use cases, so someone with a better understanding of the usages of this plugin should trace the path to follow. Other ideas could be possible that would in the future also lead to simpler usages that hide the complexity from the users.