Skip to content

Commit

Permalink
Provide an es modules build in dist/
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed May 14, 2019
1 parent 5aff6b5 commit 088f1e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/dist/
/docs/pages/dist/
/docs/img/dist/
*.es.js
*.js.map
node_modules
package-lock.json
Expand Down
6 changes: 4 additions & 2 deletions src/style-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
],
"license": "ISC",
"main": "./dist/index.js",
"module": "./dist/index.es.js",
"scripts": {
"copy-flow-typed": "cp -R ../../flow-typed .",
"build": "../../node_modules/.bin/rollup -c",
"build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm",
"prepublish": "yarn copy-flow-typed && yarn build",
"postpublish": "rm -r flow-typed dist/index.js"
},
Expand All @@ -34,5 +35,6 @@
"minimist": "0.0.8",
"rw": "^1.3.3",
"sort-object": "^0.3.2"
}
},
"sideEffects": false
}
14 changes: 11 additions & 3 deletions src/style-spec/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import unassert from 'rollup-plugin-unassert';
import json from 'rollup-plugin-json';
import {flow} from '../../build/rollup_plugins';

// Build es modules?
const esm = 'esm' in process.env;

const transforms = {dangerousForOf: true};
if (esm) {
transforms.modules = false;
}

const config = [{
input: `${__dirname}/style-spec.js`,
output: {
name: 'mapboxGlStyleSpecification',
file: `${__dirname}/dist/index.js`,
format: 'umd',
file: `${__dirname}/dist/${esm ? 'index.es.js' : 'index.js'}`,
format: esm ? 'esm' : 'umd',
sourcemap: true
},
plugins: [
Expand All @@ -25,7 +33,7 @@ const config = [{
}),
flow(),
json(),
buble({transforms: {dangerousForOf: true}, objectAssign: "Object.assign"}),
buble({transforms, objectAssign: "Object.assign"}),
unassert(),
resolve({
browser: true,
Expand Down

0 comments on commit 088f1e6

Please sign in to comment.