arielsalminen / vue-design-system

An open source tool for building UI Design Systems with Vue.js
https://vueds.com
MIT License
2.17k stars 224 forks source link

Is Vue Design System Nuxt.js compatible? #94

Closed jackbarham closed 5 years ago

jackbarham commented 6 years ago

Hello.

I'd like to use VDS with a Nuxt.js SSR build, but I can't get it to work. Is this package able work in SSR as there's no documentation regarding it. I'd prefer not spend more time trying to figure it out if it's not compatible in the first place.

Thanks.

daspete commented 6 years ago

i've implemented this system into a nuxt app... what isn't working for you?

jackbarham commented 6 years ago

It's my colleague taking this on now. I'll send him this link :)

michaelpumo commented 6 years ago

Hello @daspete - we also have it working in Nuxt (to some extent) by importing components directly into our Nuxt pages. However, we're a bit in the dark about how to import the system JS as a whole.

In a typical Vue project, we can import the design system via main.js, but Nuxt does not have a main.js. Instead, importing for Vue.use() in Nuxt is typically done via 'plugin' files. Doing this though gives the error thatsystem.js does not export a default.

So whilst we can ignore the plugin route, we're a bit worried about potential issues because of it.

Do you have an example repository for us to see how you integrated design system into Nuxt?

My own repo for Nuxt (minimal test case) is here FYI: https://github.com/michaelpumo/Nuxt-SSR

You can see that in nuxt.config.js, I commented out the plugin for Vue Design System.

arielsalminen commented 6 years ago

Hey folks! Just returned from a 5 week “offline” trip, hence the little delay here. Let me get back to this early next week when I’ve survived the jet lag :)

michaelpumo commented 6 years ago

Thanks @viljamis; much appreciated and hope you had a great holiday!

daspete commented 6 years ago

@michaelpumo hi there, i am on vacation right now, i have to look, if i have a sample repo on my pc @ home.... otherwise, i can init it in 6-7 days... sorry for the delay

michaelpumo commented 6 years ago

Hi @daspete that'd be much appreciated. I just want to sanity check that we're doing things correctly, as there's no guide on using Vue Design System with Nuxt that I can find. Cheers!

daspete commented 6 years ago

@michaelpumo i just created a new repo here: nuxt-design-system

I hope, this helps you out. The only caveat at the moment is, that there can't be SSR when you import the whole system, since some modules reference the window object. I hope, this will be fixed in any update soon

Cheers PeTe

daspete commented 5 years ago

Now i got the key... in the file /build/webpack.system.conf.js you'll need to change the libraryTarget to 'commonjs2'

After that, the designsystem is also usable with an ssr context

arielsalminen commented 5 years ago

@daspete I’m a little bit confused, how did you get it working? I actually can’t get it working myself either now and tracked the issue down to the fact that we’re currently using webpack to build the library and it doesn’t really support ES module builds (and vue-loader dropped the support for other build a while ago which is now causing this I imagine).

daspete commented 5 years ago

@viljamis i just changed the libaryTarget value into commonjs2 at /build/webpack.system.conf

with commonjs2 you can build a package with module.exports functionality.

and the built package can be imported in nuxt.js as a plugin, which can also be used server side, because, there is no more umd pattern, which includes the window object

of course, you should only change the libraryTarget, when you don't need to include the built package into another system, which depends on the umd pattern... maybe it could be added to a global config object...

arielsalminen commented 5 years ago

@daspete Hmm, yes, I tried with commonjs2 as well earlier, but couldn’t get that working either since it doesn’t do export default. So… how exactly are you importing the system? I tested your example here: https://github.com/daspete/nuxt-design-system, but no luck with that either as even when changing the libraryTarget to commonjs2 you still just get the "export 'default' (imported as 'system') was not found in 'vue-design-system' error (which makes sense as Webpack does not support exporting to ES module currently).

arielsalminen commented 5 years ago

@daspete Anyway, to makes things simpler and to fix all these issues I’m planning on switching away from Webpack for the build process.

daspete commented 5 years ago

@viljamis oh, the nuxt-design-system repo is a little outdated, since there is nuxtjs@2.0 out now... i haven't checked, if it works with nuxtjs@1.4

i will update the nuxt-design-system repo, so it works straight out of the box.

hmm, to which build system will you switch?

daspete commented 5 years ago

@viljamis i have retested and updated the repo nuxt-design-system it works straight along the readme without any hussle, but it really seams that it doesn't work with older versions of nuxt, but with 2.0 everything is fine

arielsalminen commented 5 years ago

@daspete Maybe no need to change it for now! Got the setup now working perfectly with Nuxt. I do still see that warning about missing default export, but that doesn’t seem to affect anything really. Trying to see if there’s an easy way to get rid of it. Will push a tiny release fixing a few things during the next few days hopefully.

arielsalminen commented 5 years ago

@daspete If you open browser’s console while viewing your Nuxt.js project, do you see Uncaught TypeError: Cannot assign to read only property 'exports' of object?

While everything works for me, I think that should be fixed, but I’m having a bit of a hard time right now figuring out how exactly should it be solved + what’s causing it.

I created a new related working branch: https://github.com/viljamis/vue-design-system/pull/118

Would love to hear if you or anyone else has any ideas on what to do to fix that typeError. It’s related to the fact that Webpack/commonjs2 libraryTargets adds the exports.default, but I’m not sure what would be the optimal way to solve this.

arielsalminen commented 5 years ago

I added a note to FAQ about Nuxt not being supported right now because of the few errors it’s throwing once the system is imported and used: https://github.com/viljamis/vue-design-system/wiki/Frequently-Asked-Questions-(FAQ)#does-vue-design-system-work-with-nuxtjs

arielsalminen commented 5 years ago

@jackbarham @michaelpumo Do you have anything against if if I rename this issue to “Nuxt.js compatibility” as I don’t see the same issues when using a completely custom SSR setup?

arielsalminen commented 5 years ago

@daspete @jackbarham @michaelpumo Ok, I got the whole setup working perfectly with Nuxt now. Releasing a new version soon and a new “official” demo.

arielsalminen commented 5 years ago

Happy to tell you folks that I’ve added Nuxt.js support and that there’s an official demo now with small-ish instructions. See release notes: https://github.com/viljamis/vue-design-system/releases/tag/3.5.2