When working with openlayers, I use the plain JS (no modules) distribution by using
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.9.0/build/ol.js">
or a local copy of ol.js and debug at will in my local browser.
When everything is working with declarations like
var map = new ol.Map({ ...});
var mySource = new ol.source.Vector();
etc ...
I'd like to be able to build a custom-ol.js smaller than ol.js containing just what I use.
I tried different approach without great success. Installing a development environment in Node with a simple main.js importing just what I need seemed a good solution:
import {Map, View} from 'ol';
import Vector from 'ol/layer/Vector';
...
However, when building with node as explained in https://openlayers.org/en/latest/doc/tutorials/bundle.html, using the numerous options offered (Vite, Webpack, RollUp, etc ...), I face one of these two issues:
- Either custom-ol.js is built as a module, and local development is no longer possible
- Or custom-ol.js is built as a plain JS file, without modules, but I can't have syntax like ol.source.Vector() working
I also tried to build Openlayers from source with 'npm run build-legacy', but it's cumbersome to try-and-error guess which source is to be excluded.
I really miss a good tutorial to manually build a minimal custom Openlayers library while keeping the ol.xxx.yyy-style declarations.