[英]How to use npm-installed cesium for browser
Cesium is now on npm. 铯现在在npm。 After npm install cesium
-ing into my project, all codes go into node_modules
. 在npm install cesium
-ing到我的项目之后,所有代码都进入node_modules
。
In the cesium hello world , it includes cesium
by something like <script src="your/path/to/Cesium.js"></script>
在cesium hello world中 ,它包含了类似<script src="your/path/to/Cesium.js"></script>
类的cesium
。
My question is, what additional steps I need to do in order to use cesium from html? 我的问题是,为了从html中使用cesium,还需要做些什么?
There are a couple of ways. 有几种方法。 If the node_modules
folder itself is being served, you can just pull Cesium from there. 如果正在提供node_modules
文件夹本身,您可以从那里拉出node_modules
。 During debugging, use the un-minified version: 在调试期间,使用未缩小的版本:
<script src="node_modules/cesium/Build/CesiumUnminified/Cesium.js"></script>
<style>
@import url(node_modules/cesium/Build/CesiumUnminified/Widgets/widgets.css);
</style>
But for production, use the minified version: 但是对于生产,请使用缩小版本:
<script src="node_modules/cesium/Build/Cesium/Cesium.js"></script>
<style>
@import url(node_modules/cesium/Build/Cesium/Widgets/widgets.css);
</style>
There's another option as well. 还有另一种选择。 You can use npm
to pull down a copy of require.js
, and then require in only the specific modules of Cesium you need, from the Cesium source tree in node_modules\\cesium\\Source
. 您可以使用npm
来下载require.js
的副本,然后从node_modules\\cesium\\Source
中的node_modules\\cesium\\Source
源树中仅需要require.js
的特定模块。 This results in your project including less JavaScript than pulling in the whole combined file, and allows easier debugging, because of the separate files. 这导致您的项目包含的JavaScript少于拉入整个组合文件,并且由于单独的文件,因此可以更轻松地进行调试。 But it results in more network requests, so you wouldn't want this directly in a production environment without some kind of build system to combine and minify the files you use. 但它会导致更多的网络请求,因此如果没有某种构建系统来组合和缩小您使用的文件,您不会直接在生产环境中使用它。
There's some additional detail on the blog post introducing npm cesium . 在介绍npm cesium的博客文章中有一些额外的细节。 (written by Matt Amato, who also provided some comments below) (由Matt Amato撰写,他也在下面提供了一些评论)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.