Skip to content

Commit

Permalink
bundle ES6 version
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Apr 3, 2017
1 parent 147e6e1 commit 41effa1
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 82 deletions.
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"presets": [
"latest",
["latest", {
"es2015": {
"modules": false
}
}],
"stage-0"
],
"plugins": [
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Install it with NPM or Bower:
```shell
npm install openlayers ol-tilecache
bower install openlayers ol-tilecache
// if you plan use ES2015 versionof the plugin
npm install ol
```
Or download the latest versions of OpenLayers and ol-tilecache and add them with script tags:
Expand All @@ -26,26 +28,24 @@ Or download the latest versions of OpenLayers and ol-tilecache and add them with
```
### Note
**Built version of ol-tilecache from `dist` directory depends on [openlayers](https://www.npmjs.com/package/openlayers) package,
it is imported by default in Node or Browser env.
If you use bundlers like Webpack with Babel you should install [ol](https://www.npmjs.com/package/ol) manually
because ES2015 module from `src` directory will be used that depends on [ol](https://www.npmjs.com/package/ol) package.
You can add an alias to Webpack config to force using of built version: `ol-tilecache: 'ol-tilecache/dist/bundle'`.**
**Plugin is available in 2 versions: as UMD module and as ES2015 module:**
- **UMD version (`dist/bundle[.min].js`) should be used with [openlayers](https://www.npmjs.com/package/openlayers) package.**
- **ES2015 version (`dist/bundle.es.js`) should be used with [ol](https://www.npmjs.com/package/ol) package (you should
install it manually)``**
## Usage
Plugin may be used as UMD module or ES2015 module:
```js
// Use as ES2015 module (based on NPM package `ol`)
// imports source files as is from `src` directory by default
// assumes bundling with Webpack or Browserify
// Use as ES2015 module (based on NPM package `ol`)
import Map from 'ol/map'
...
import * as tileCacheUrlFn from 'ol-tilecache'
import tileCacheUrlFn from 'ol-tilecache'
// or only what you need
import { createTileUrlFunction } from 'ol-tilecache'

// Use as CommonJS module (based on NPM package `openlayers`) without bundling
// imports UMD module from `dist` directory by default
// Use as UMD module (based on NPM package `openlayers`)
const ol = require('openlayers')
...
const tileCacheUrlFn = require('ol-tilecache')
Expand Down
26 changes: 25 additions & 1 deletion build/rollup.es.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,32 @@ const replace = require('rollup-plugin-replace')
const babel = require('rollup-plugin-babel')
const packageJson = require('../package.json')

const nodeEnv = process.env.NODE_ENV || 'development'
const banner =
`/*!
${packageJson.description}
@package ${packageJson.name}
@author ${packageJson.author}
@version ${packageJson.version}
@licence MIT https://opensource.org/licenses/MIT
@copyright (c) 2016-${new Date().getFullYear()}, ${packageJson.author}
*/`

module.exports = {
format: 'es',
entry: path.join(__dirname, '../src/index.js'),
dest: path.join(__dirname, '../dist/bundle.es.js'),
format: 'es'
banner,
plugins: [
replace({
'process.env.NODE_ENV': `'${nodeEnv}'`,
PKG_VERSION: `'${packageJson.version}'`
}),
babel()
],
external (id) {
return /^(openlayers|ol.*)$/i.test(id)
},
sourceMap: true
}
301 changes: 301 additions & 0 deletions dist/bundle.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41effa1

Please sign in to comment.