[英]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.