chrisvfritz / hello-vue-components

An example component library built with Vue CLI 3.
MIT License
315 stars 42 forks source link

Example for SSR use? #9

Open DominicGebhart opened 5 years ago

DominicGebhart commented 5 years ago

Really great Example,

i also got it to work in my Nuxt.js Enviroment but without the SSR :(
I'm trying since Days to get it work in SSR mode. Could you provide some Information/Tipps or even a Example for that kind of case.

When i load it, i get the Error: 'document' not defined, because its server rendered. As far as i found out is that it may be achivable with the target set to 'node'. In the packaged index.js i find some document uses from the vue-style-loader and and a line saying: 'vue-style-loader cannot be used in a non-browser environment. ' + "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment."

But until now i didn't managed to set the target of the build

Any ideas? :)

chrisvfritz commented 5 years ago

The module build should automatically work with SSR, because it relies on the user for compilation and they can specify target: 'node' in their configuration.

The CJS and UMD builds are a different story though. Personally, I would just tell SSR users not to use them. However, if you wanted to assume an SSR context, then I believe adding config.target('node') to the chainWebpack function in vue.config.js should work. If you want to separate versions for SSR and the browser, then you'd probably want to use something like config.target(process.env.WEBPACK_TARGET) instead and then update build-lib.js create SSR builds.

Does that make sense?