我正在使用ParcelJS开发服务器来开发NodeJS应用程序。该应用程序将OpenLayers与OSRM一起使用,以在地图上用户定义的点之间提供路由。这些点由图标标记指示,这些图标标记是通过从js文件中的磁盘导入来加载的。我目前正在设计图标的样式,重新加载页面后,我想查看更新后的图像。但是,当我在更改脚本文件时ParcelJS更新它们时,除非重新启动包裹服务器,否则图像资产不会更新。
有什么方法可以使我的ParcelJS开发服务器在更改时也更新图像资产?
问题并非专门基于我的代码,但为完整起见,我的基本代码如下:
import markerpng from './images/marker.png';
// I'm saving markers to later change/delete them
var markers = new Array();
// One layer containing all the markers. It's initialized with zero features
var marker_layer = new VectorLayer({
map: map,
source: new VectorSource({
features: []
})
});
// Add a marker to the vector layer, at the given lat/lon coordinates.
// The marker icon is given by the filename
function addMarker(coordinates, filename) {
markers[markers.length] = new Feature({
geometry: new Point(coordinates);
});
markers[markers.length-1].setStyle(new Style({
image: new Icon({
src: filename,
anchor: [0.5, 1] // To set the bottom-center as anchorpoint
});
}));
marker_layer.getSource().addFeature(markers[markers.length-1]);
}
// Add one marker
addMarker([52.2, 6.8], markerpng);
导入图像以获取开发环境中的相对URL(在该环境中,文件的临时名称与磁盘上的名称不同)可以在任何地方使用。代码本身可以正常工作。
我的package.json看起来像这样
{
"name": "maps",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html",
"build": "parcel build --public-url . index.html"
},
"dependencies": {
"images": "^3.0.2",
"ol": "^5.3.3"
}
}
然后我用
启动开发服务器yarn run start
我不知道ParcelJS是否具有对图像资产进行实时更新的能力,而且我无法在其文档或其他任何地方找到有关它的任何内容,因此这里的问题是:)
在此先感谢您的帮助!