Skip to content

Commit

Permalink
Setup rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Feb 22, 2018
1 parent ed695ab commit 4a30c29
Show file tree
Hide file tree
Showing 9 changed files with 1,913 additions and 1,871 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/src_untyped
/rollup/build/
/docs/components/api.json
/dist/mapbox-gl-dev.js
/dist/mapbox-gl.js
Expand Down
20 changes: 20 additions & 0 deletions build/rollup_plugin_minify_style_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

function replacer(k, v) {
return (k === 'doc' || k === 'example' || k === 'sdk-support') ? undefined : v;
}

export default function minifyStyleSpec() {
return {
name: 'minify-style-spec',
transform: (source, id) => {
if (!/style\-spec[\\/]reference[\\/]v[0-9]+\.json$/.test(id)) {
return;
}

return {
code: JSON.stringify(JSON.parse(source), replacer, 0),
map: {mappings: ''}
};
}
};
}
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"package-json-versionify": "^1.0.2",
"pbf": "^3.0.5",
"quickselect": "^1.0.0",
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-unassert": "^0.2.0",
"rw": "^1.3.3",
"shuffle-seed": "^1.1.6",
"sort-object": "^0.3.2",
Expand Down Expand Up @@ -94,6 +96,13 @@
"remark-html": "^5.0.1",
"remark-react": "^4.0.1",
"request": "^2.79.0",
"rollup": "^0.56.2",
"rollup-plugin-browserify-transform": "^1.0.1",
"rollup-plugin-buble": "^0.18.0",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-node-resolve": "3.0.0",
"rollup-plugin-uglify": "^3.0.0",
"sinon": "^2.1.0",
"slugg": "^1.2.1",
"st": "^1.2.0",
Expand Down Expand Up @@ -131,6 +140,7 @@
"watch-dev": "watchify src/index.js --debug --ignore-transform unassertify --standalone mapboxgl --outfile dist/mapbox-gl-dev.js --verbose",
"watch-style-property-editor": "watchify debug/style_property_editor.js --debug -o debug/style_property_editor_generated.js --standalone StylePropertyEditor --verbose",
"build-min": "browserify src/index.js --debug --plugin [minifyify --map mapbox-gl.js.map --output dist/mapbox-gl.js.map] --standalone mapboxgl | derequire > dist/mapbox-gl.js && tap --no-coverage test/build/min.test.js",
"build-rollup": "rollup -c",
"build-token": "browserify debug/access_token.js --debug --transform envify > debug/access_token_generated.js",
"build-benchmarks": "BENCHMARK_VERSION=${BENCHMARK_VERSION:-\"$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --short=7 HEAD)\"} browserify bench/benchmarks.js --debug --transform envify --outfile bench/benchmarks_generated.js --verbose",
"watch-benchmarks": "BENCHMARK_VERSION=\"$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --short=7 HEAD)\" watchify bench/benchmarks.js --debug --transform envify --outfile bench/benchmarks_generated.js --verbose",
Expand Down
77 changes: 77 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import flow from 'rollup-plugin-flow';
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import unassert from 'rollup-plugin-unassert';
import json from 'rollup-plugin-json';
import browserifyPlugin from 'rollup-plugin-browserify-transform';
import brfs from 'brfs';
import uglify from 'rollup-plugin-uglify'
import minifyStyleSpec from './build/rollup_plugin_minify_style_spec';

const production = process.env.BUILD === 'production';
const outputFile = production ? 'dist/mapbox-gl.js' : 'dist/mapbox-gl-dev.js';

const plugins = [
flow(),
minifyStyleSpec(),
json(),
buble({transforms: {dangerousForOf: true}, objectAssign: "Object.assign"}),
unassert(),
resolve({
browser: true,
preferBuiltins: false
}),
browserifyPlugin(brfs, {
include: 'src/shaders/index.js'
}),
commonjs({
namedExports: {
'@mapbox/gl-matrix': ['vec3', 'vec4', 'mat2', 'mat3', 'mat4']
}
})
]

if (production) {
plugins.push(uglify());
}

const config = [{
input: ['src/index.js', 'src/source/worker.js'],
output: {
name: 'mapboxgl',
dir: 'rollup/build',
format: 'amd',
sourcemap: 'inline'
},
experimentalCodeSplitting: true,
plugins
}, {
input: 'rollup/main.js',
output: {
name: 'mapboxgl',
file: outputFile,
format: 'umd',
sourcemap: production ? true : 'inline'
},
plugins: production ? [] : [uglify()],
intro: `
let shared, worker, mapboxgl;
function define(_, module) {
if (!shared) {
shared = module;
} else if (!worker) {
worker = module;
} else {
const workerBundleString = 'const sharedModule = {}; (' + shared + ')(sharedModule); (' + worker + ')(sharedModule);'
const sharedModule = {};
shared(sharedModule);
mapboxgl = module(sharedModule);
mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));
}
}
`
}];

export default config
5 changes: 5 additions & 0 deletions rollup/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './build/chunk1';
import './build/worker';
import './build/index';

export default mapboxgl;
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Point from '@mapbox/point-geometry';
import Evented from './util/evented';
import config from './util/config';
import {setRTLTextPlugin} from './source/rtl_text_plugin';
import createWorker from './source/worker';

const exported = {
version,
Expand Down Expand Up @@ -55,9 +54,7 @@ const exported = {

set accessToken(token: string) {
config.ACCESS_TOKEN = token;
},

_createWorker: createWorker
}
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ class Worker {
}
}

export default function createWorker(self: WorkerGlobalScopeInterface) {
return new Worker(self);
};
/* global self */
new Worker(self);

1 change: 1 addition & 0 deletions src/style-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"copy-flow-typed": "cp -R ../../flow-typed .",
"build": "../../node_modules/.bin/browserify style-spec.js --standalone=mapboxGlStyleSpecification | ../../node_modules/.bin/derequire > dist/index.js",
"rollup": "rollup -c",
"prepublish": "in-publish && yarn copy-flow-typed && yarn build || not-in-publish",
"postpublish": "in-publish && rm -r flow-typed dist/index.js || not-in-publish"
},
Expand Down
Loading

0 comments on commit 4a30c29

Please sign in to comment.