问题描述
是否可以将 Leaflet 与 angular/universal 一起使用?如何避免在服务器中构建 Leaflet?
Is it possible to use Leaflet with angular/universal? How can I avoid to build Leaflet within server?
npm run build:prod
后生成 dist 文件夹.但是当我运行 node server.js
时出现以下错误:
After npm run build:prod
dist folder is generated. But when I run node server.js
I get following error:
var requestFn = window.requestAnimationFrame ||getPrefixed('RequestAnimationFrame') ||超时延迟;窗户不是定义.
推荐答案
我通过用 window、navigator
和 document
解决了这个问题a href="https://www.npmjs.com/package/mock-browser" rel="nofollow noreferrer">模拟浏览器
I solved this by mocking window
, navigator
and document
with Mock Browser
只需安装模拟浏览器pacakgenpm i 模拟浏览器
Just install the mock browser pacakge npm i mock-browser
并将以下代码添加到您的 server.ts
中:
And add the following code to your server.ts
:
const MockBrowser = require('mock-browser').mocks.MockBrowser;
const mock = new MockBrowser();
global['window'] = mock.getWindow();
global['document'] = mock.getDocument();
global['navigator'] = mock.getNavigator();
这篇关于如何在传单中使用@angular/universal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!