We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
mini-css-extract-plugin
extract-css-chunks-webpack-plugin
document is not defined
是由于运行上述插件后异步导入组件时服务端代码会执行 document.createElement 方法插入 link 标签,但是此时 document 对象为 undefined,因此会出现该错误。作为验证,当你检查打包后的服务端代码时会发现有大量多余的 document 对象方法,服务端代码则无法运行。
使用 vue-style-loader 替代,但是无法抽取 CSS 代码
vue-style-loader
null-loader or css-loader/locals (for CSS modules),未验证
null-loader
css-loader/locals
重写 mini-css-extract-plugin的getCssChunkObject方法,已验证可完美解决
getCssChunkObject
class ServerMiniCssExtractPlugin extends MiniCssExtractPlugin { getCssChunkObject(mainChunk) { return {}; } }
https://segmentfault.com/q/1010000016459292
vue ssr document is not defined vuejs/vue-router#2380
Async loading without document context throws errors webpack-contrib/mini-css-extract-plugin#48 (comment)
mini-css-extract-plugin with SSR. webpack-contrib/mini-css-extract-plugin#90
extract-css-chunks-webpack-plugin文档中提到该插件 SSR 友好,应当也会支持 SSR 的异步组件,但直接替换mini-css-extract-plugin并没有解决问题,不清楚是否需要进行特殊配置
The text was updated successfully, but these errors were encountered:
fix(解决异步组件生产环境报错问题): vue SSR server.bundle.js报错document is not defined
64b2785
由于运行mini-css-extract-plugin提取CSS,异步导入组件时服务端代码会执行 document.createElement 方法插入 link 标签,但是此时 document 对象为 undefined,因此会出现该错误 fix #6
fix(build): fix bug
0dfa4ae
fix #6
for that unsolved problem you need to add
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
in your webpack.server config file plugins then it just works
I don't know exactly what's the relation between them.
Sorry, something went wrong.
No branches or pull requests
Vue Webpack4 SSR server.bundle.js 报错 document is not defined
Detailed description of the problem
mini-css-extract-plugin
、extract-css-chunks-webpack-plugin
等用来抽取 CSS 代码的 webpack 插件document is not defined
Problem Causes
是由于运行上述插件后异步导入组件时服务端代码会执行 document.createElement 方法插入 link 标签,但是此时 document 对象为 undefined,因此会出现该错误。作为验证,当你检查打包后的服务端代码时会发现有大量多余的 document 对象方法,服务端代码则无法运行。
Solution
Indirect Method:
Direct Method:
使用
vue-style-loader
替代,但是无法抽取 CSS 代码null-loader
orcss-loader/locals
(for CSS modules),未验证重写
mini-css-extract-plugin
的getCssChunkObject
方法,已验证可完美解决Reference
https://segmentfault.com/q/1010000016459292
vue ssr document is not defined vuejs/vue-router#2380
Async loading without document context throws errors webpack-contrib/mini-css-extract-plugin#48 (comment)
mini-css-extract-plugin with SSR. webpack-contrib/mini-css-extract-plugin#90
Unsolved
extract-css-chunks-webpack-plugin
文档中提到该插件 SSR 友好,应当也会支持 SSR 的异步组件,但直接替换mini-css-extract-plugin
并没有解决问题,不清楚是否需要进行特殊配置Supplement
The text was updated successfully, but these errors were encountered: