首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenLayers 6和RollupJS食谱

OpenLayers 6和RollupJS食谱
EN

Stack Overflow用户
提问于 2019-10-28 23:28:06
回答 1查看 230关注 0票数 1

我正在尝试使用RollupJS创建OpenLayers 6的生产版本。我想生成一个最小化的ES6模块,我可以从这个模块导入代码中的类……我不想把我的代码和核心的OL类混在一起。据我所见,默认的OpenLayers捆绑包、包裹和其他选项不能管理这一点。

在使用ol-rollup (https://github.com/openlayers/ol-rollup)的OpenLayers-5中,所有这些都工作得很好。但是,如果我更新到OpenLayers-6 & RollupJS <= 1.26.0 (https://github.com/flavour/ol-rollup),那么我会得到以下错误:

代码语言:javascript
复制
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en#error-this-is-undefined
node_modules\ol\layer\Tile.js
1: var __extends = (this && this.__extends) || (function () {
                    ^
2:     var extendStatics = function (d, b) {
3:         extendStatics = Object.setPrototypeOf ||
...and 1 other occurrence
node_modules\ol\source\XYZ.js
2:  * @module ol/source/XYZ
3:  */
4: var __extends = (this && this.__extends) || (function () {
                    ^
5:     var extendStatics = function (d, b) {
6:         extendStatics = Object.setPrototypeOf ||
...and 1 other occurrence
node_modules\ol\AssertionError.js
1: var __extends = (this && this.__extends) || (function () {
                    ^
2:     var extendStatics = function (d, b) {
3:         extendStatics = Object.setPrototypeOf ||
...and 1 other occurrence
...and 98 other files

关于这一点,RollupJS网站有以下内容:https://rollupjs.org/guide/en/#error-this-is-undefined https://rollupjs.org/guide/en/#danger-zone

我不知道如何使用options.context或options.moduleContext来修复这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-18 19:58:28

该问题是由用于将OpenLayers转换为ES5的TypeScript编译器的类继承代码引起的。一种选择是使用以下命令配置rollup

代码语言:javascript
复制
onwarn: function(warning, superOnWarn) {
  if (warning.code === 'THIS_IS_UNDEFINED') {
    return;
  }
  superOnWarn(warning);
}

官方的OpenLayers+Rollup配方(https://github.com/openlayers/ol-rollup)最近已经更新了这一变化。

另一种选择是导入源模块,而不是在应用程序中导入已转换的模块。因此,例如,不是

代码语言:javascript
复制
import Map from 'ol/Map'

你可以

代码语言:javascript
复制
import Map from 'ol/src/Map'

有关此问题的更多信息,请参阅https://github.com/openlayers/openlayers/issues/10245

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58593754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档