Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何让自己写的组件支持 SSR? #3660

Closed
falstack opened this issue Mar 18, 2019 · 5 comments
Closed

如何让自己写的组件支持 SSR? #3660

falstack opened this issue Mar 18, 2019 · 5 comments

Comments

@falstack
Copy link

falstack commented Mar 18, 2019

What problem does this feature solve?

我使用 vue-cli 3 写了一个组件:vue-flow-render
如果我把 src 下面的两个组件 copy 到一个 SSR 的项目中,它可以 work
但我把这个包发布到 npm 上再引入后,就会报错:document is not defined
我不知道我该去修改什么地方,可以告诉我吗?

What does the proposed API look like?

需要如何修改 vue.config.js 就能够支持 build 后的包能在 SSR 的时候运行

@troy351
Copy link
Contributor

troy351 commented Mar 19, 2019

SSR运行在node环境,node环境不存在全局变量document,需要使用jsdom

@falstack
Copy link
Author

我的组件里需要用到 document 和 window 的都做了环境判断,并且直接 import 组件源码是 SSR work 的,但是发布到 npm 之后,通过包来 import 就无法 work 了

@haoqunjiang
Copy link
Member

因为 css: { extract: false }

@falstack
Copy link
Author

@sodatea 是的,已经解决了,谢谢

@falstack
Copy link
Author

@sodatea 如果这里有 css 样式,但是又不想在 import component 的时候额外 import style 该怎么做呢?

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

No branches or pull requests

3 participants