Skip to content

Instantly share code, notes, and snippets.

@tschaub
Last active April 25, 2019 22:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tschaub/8beb328ea72b36446fc2198d008287de to your computer and use it in GitHub Desktop.
Save tschaub/8beb328ea72b36446fc2198d008287de to your computer and use it in GitHub Desktop.
OpenLayers + Rollup
/node_modules/
bundle.js

OpenLayers + Rollup

This example demonstrates how the ol package can be used with Rollup.

Clone the project.

git clone git@gist.github.com:8beb328ea72b36446fc2198d008287de.git ol-rollup

Install the project dependencies.

cd ol-rollup
npm install

Create a bundle for the browser.

npm run build

Open index.html to see the result.

open index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Using OpenLayers with Rollup</title>
<link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" type="text/css">
<style>
html, body {
margin: 0;
height: 100%;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="./bundle.js"></script>
</body>
</html>
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
new Map({
target: 'map',
layers: [
new TileLayer({
source: new XYZ({
url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
})
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
{
"name": "ol-rollup",
"version": "1.0.0",
"description": "Example using OpenLayers with Rollup",
"scripts": {
"start": "rollup --config rollup.config.js --watch",
"build": "rollup --config rollup.config.js"
},
"devDependencies": {
"rollup": "^0.61.2",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-terser": "^1.0.1"
},
"dependencies": {
"ol": "^5.0.0"
}
}
import cjs from 'rollup-plugin-commonjs';
import node from 'rollup-plugin-node-resolve';
import {terser} from 'rollup-plugin-terser';
const production = !process.env.ROLLUP_WATCH;
export default {
input: 'main.js',
output: [
{file: 'bundle.js', format: 'iife'}
],
plugins: [
node(),
cjs(),
production && terser()
]
};
@tstaapp
Copy link

tstaapp commented Jan 9, 2018

is good

@interwebjill
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment