Javascript 使用Webpack包含具有全局引用的外部脚本

Javascript 使用Webpack包含具有全局引用的外部脚本,javascript,leaflet,webpack-2,Javascript,Leaflet,Webpack 2,我正在使用Webpack2打包一些旧的javascript代码。此代码使用传单1.0库,还包括一个传单插件(名为Google.js),该插件仅引用传单公开的全局L变量 在当前html页面中,先加载传单,然后加载插件(Google.js),然后通过脚本标记加载map1.jscode。这一切都很好 我创建了以下webpack.config.js: var path = require('path'); module.exports = { devtool: 'cheap-eval-source

我正在使用Webpack2打包一些旧的javascript代码。此代码使用传单1.0库,还包括一个传单插件(名为Google.js),该插件仅引用传单公开的全局
L
变量

在当前html页面中,先加载传单,然后加载插件(Google.js),然后通过脚本标记加载
map1.js
code。这一切都很好

我创建了以下
webpack.config.js

var path = require('path');

module.exports = {
  devtool: 'cheap-eval-source-map',
  entry: {
    map1: './js/map1.js'
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};
map1.js
中,我添加了以下内容来定义webpack的依赖性要求:

import bootstrap from 'bootstrap';
import leaflet from 'leaflet';
require('script-loader!./lib/Google.js');
bundle.js
构建时没有问题,但是当页面加载时,我得到:

Uncaught TypeError: Cannot read property 'call' of undefined at NewClass.whenReady (eval at (bundle.js:79), :3641:12) at NewClass.addLayer (eval at (bundle.js:79), :4057:8) at eval (eval at (bundle.js:176), :118:7) at eval (eval at (bundle.js:176), :232:3) at Object. (bundle.js:176) at __webpack_require__ (bundle.js:20) at bundle.js:66 at bundle.js:69 未捕获的TypeError:无法读取未定义的属性“call” 在NewClass.whenrady(eval at(bundle.js:79),:3641:12) 在NewClass.addLayer(eval at(bundle.js:79),:4057:8) 评估时(评估时(bundle.js:176),:118:7) 评估时(评估时(bundle.js:176),:232:3) 反对。(bundle.js:176) at\uuuuu网页包\uuuuuu需要(bundle.js:20) 在bundle.js:66 在bundle.js:69 查看发生错误的第79行:

eval(“var\uuuuu网页包\u AMD\u DEFINE\u工厂\uuuuuu,\uuuuu网页包\u AMD\u DEFINE\u结果\uuuuuuuuu;/*\ n传单1.0.3,用于交互式地图的JS库…


对传单代码的评估似乎失败了。我应该做些什么来将传单合并到我的网页构建中吗?

我刚刚尝试了一个非常简单的网页项目,使用了以下方法,效果非常好:

import 'leaflet';
import 'leaflet.gridlayer.googlemutant';

var map = L.map('map').setView([0,0],0);
var roadMutant = L.gridLayer.googleMutant({                     
  maxZoom: 24,                  
  type:'roadmap'                
}).addTo(map);

只要你在HTML.And
npm安装传单传单.gridlayer.GoogleVariant
中单独引用GMaps JS API,那就行了。

看起来源地图eval有问题,你真的需要“便宜的eval源地图”还是可以是任何源地图配置?你试过了吗改为“内联源代码映射”?我删除了
webpack.config.js
中的
devtool
行。很遗憾,在硬刷新时出现了相同的错误消息。