简体   繁体   English

webpack + leaflet插件

[英]webpack + leaflet plugin(s)

I have a requireJs-based library, that exports object T , which holds Leaflet object L . 我有一个基于requireJs的库,它导出对象T ,它保存Leaflet对象L. And I have a Leaflet plugin ( this , in my case, but valid for any other), which adds some functions to the global object L . 我有一个Leaflet插件(在我的情况下, 对任何其他都有效),它为全局对象L添加了一些函数。 And I have my module, where I want to use object T with extended L . 我有我的模块,我想在其中使用带有扩展L的对象T. Question: how to gracefully do it with Webpack? 问题:如何使用Webpack优雅地完成它? I could modify the plugin, to import L from the first library, but anyway don't understand how to plug it in to my module. 我可以修改插件,从第一个库导入L,但无论如何都不明白如何将它插入我的模块。 And not sure that this is the best way. 并不确定这是最好的方法。

PS I saw this thread, and this as well, but didn't find a good way there. PS我看到这个帖子, 也是,但没有找到一个好方法。 I don't want to use additional < script> tags, and this is quite rambled to have statements like this: 我不想使用额外的<script>标签,这样的语句非常粗糙:

import 'my.leflet.library';
import 'leaflet.plugin';

somewhere in the source - instead, I would prefer to add something to the configuration, that will extend L object right after 'my.leaflet.library' would be loaded, and any module, that would import 'my.leaflet.library' will have T with modified L . 在源代码中的某个地方 - 相反,我更愿意在配置中添加一些内容,这将在加载'my.leaflet.library'之后立即扩展L对象,并且任何将导入'my.leaflet.library'的模块将T改为L。 Is it possible? 可能吗?

This is my webpack config for Vue (vue.config.js), you can probably adapt it for your needs. 这是我的Vue(vue.config.js)的webpack配置,你可以根据自己的需要调整它。

const webpack = require('webpack')

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        L: 'leaflet',
        'window.L': 'leaflet',
      })
    ],
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Webpack的define插件:变量未定义 - Webpack's define plugin: variable is not defined Rails Leaflet Webpack 空白页 - Rails Leaflet Webpack blank page 为什么样式加载器被用作Webpack的ExtractSass插件的后备? - Why is style-loader used as a fallback with Webpack's ExtractSass plugin? 传单标记集群插件未加载 - Leaflet markercluster plugin not loading 已弃用的 Webpack 的 i18n 插件和加载器的替代方案 - Alternatives to deprecated Webpack's i18n plugin and loader 将 TerserWebpackPlugin webpack 插件的源 map 选项设置为 true 会显着增加 webpack 构建时间 - Setting the TerserWebpackPlugin webpack plugin's source map option to true significantly increases webpack build time 在特定的 leaflet 版本上使用插件扩展 leaflet - Extend leaflet with plugin on specific leaflet version 如何将 Webpack 4 插件转换为 Webpack 5 - How to convert Webpack 4 plugin to Webpack 5 如何使用 Leaflet 的 Geosearch 插件获取常规表单字段以自动完成地理搜索? - How to get a regular form field to autocomplete a geosearch with Leaflet's Geosearch plugin? Leaflet的集群插件:如何仅在具有相同属性时对标记进行分组 - Leaflet's cluster plugin: how to group markers only when they have the same property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM