Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

server-bundle created by vueify does not run in node #165

Closed
mediafreakch opened this issue Dec 12, 2016 · 2 comments
Closed

server-bundle created by vueify does not run in node #165

mediafreakch opened this issue Dec 12, 2016 · 2 comments

Comments

@mediafreakch
Copy link

Hey,

I'm trying to get the vue server-side rendering working in a browserify pipeline. Has anyone done this before? Is it possible with vueify?

It seems that the bundle generated by vueify cannot be executed by node. I'm getting this error in the console when accessing route /:

ReferenceError: document is not defined
    at Object.exports.insert (__vue_ssr_bundle__:10168:14)
    at Object.21../components/Topbar.vue (__vue_ssr_bundle__:11122:65)
    at s (__vue_ssr_bundle__:1:682)
    at __vue_ssr_bundle__:1:733
    at Object.22../App.vue (__vue_ssr_bundle__:11170:12)
    at s (__vue_ssr_bundle__:1:682)
    at __vue_ssr_bundle__:1:733
    at Object.<anonymous> (__vue_ssr_bundle__:11660:12)
    at Object.31../app (__vue_ssr_bundle__:11703:4)
    at s (__vue_ssr_bundle__:1:682)

Probably from this line

Yes, I use single file .vue components that contain styles. But shouldn't vue-server-renderer be smart enough not to run this in node?

Using vueify 9.4.0 and vue 2.1.4

@mediafreakch
Copy link
Author

Ok I figured that you actually need to pass VUE_ENV=server as a environment variable to browserify when building the server-bundle. In my package.json, that looks like this: VUE_ENV=server browserify -e src/server-entry.js -o dist/server-bundle.js -t vueify

It's not documented anywhere. Would be nice to have it documented somewhere...

@mediafreakch
Copy link
Author

mediafreakch commented Dec 13, 2016

I had to supply browserify with the --no-browser-field, --bare and --standalone server flags too. Where server can be any name you choose, this will just export the server-bundle under the given name. My browserify command now looks like this:

VUE_ENV=server browserify --bare --no-browser-field --standalone server -e src/server-entry.js -o dist/server-bundle.js -t vueify -t babelify

The resulting bundle now works with the createBundleRenderer of vue-server-renderer.

Hope that helps anyone trying to setup server-side-rendering with vue and browserify!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant