使用 NPM 和 Webpack 的开放层

Open Layers with NPM and Webpack

我正在尝试使用 NPM 和 Webpack 将 Open Layers 3 导入到我的应用程序中进行捆绑,但我收到错误消息并且地图未呈现:

./~/openlayers/dist/ol.js Critical dependencies: 567:411-418 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results. @ ./~/openlayers/dist/ol.js 567:411-418

使用以下方法导入开放层:

import ol from 'openlayers';

我尝试在 Webpack 中使用 noParse 选项:noParse: /dist\/ol.js/ 但没有成功。

如何将 Open Layers 与 NPM 和 Webpack 一起使用?

显然我必须找到它的确切位置:

工作解决方案:

var Path = require("path");
noParse: [Path.join(__dirname, "node_modules/openlayers/dist/ol.js")]