Create a gist now

Instantly share code, notes, and snippets.

@tschaub /.gitignore
Last active Jan 10, 2018

What would you like to do?
OpenLayers, Rollup, and Closure Compiler

OpenLayers, Rollup, and Closure Compiler

This example demonstrates how the ol@beta package can be used with Rollup and the Closure Compiler in advanced mode.

Note that the Compiler takes a while to run.

Clone the project.

git clone ol-rollup-closure

Install the project dependencies.

cd ol-rollup-closure
npm install

Create a bundle for the browser.

npm run build

Open index.html to see the result.

open index.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>Using OpenLayers with Rollup and the Closure Compiler</title>
<link rel="stylesheet" href="" type="text/css">
html, body {
margin: 0;
height: 100%;
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
<div id="map"></div>
<script src="./bundle.js"></script>
import Map from 'ol/map';
import View from 'ol/view';
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}{z}/{x}/{y}.png'
view: new View({
center: [0, 0],
zoom: 2
"name": "ol-rollup-closure",
"version": "1.0.0",
"description": "Example using OpenLayers with Rollup and Closure Compiler",
"scripts": {
"build": "rollup --config rollup.config.js"
"devDependencies": {
"rollup": "^0.51.3",
"rollup-plugin-closure-compiler-js": "^1.0.5",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0"
"dependencies": {
"ol": "^4.1.0"
import closure from 'rollup-plugin-closure-compiler-js';
import common from 'rollup-plugin-commonjs';
import node from 'rollup-plugin-node-resolve';
module.exports = {
input: 'main.js',
output: [
{file: 'bundle.js', format: 'es'}
plugins: [
compilationLevel: 'ADVANCED',
warningLevel: 'QUIET'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment