From 89426fdca9273753c293432d901c5b0794a5607d Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 15 Mar 2019 17:05:14 +0200 Subject: [PATCH 1/6] introduce static worker version of the bundle --- build/banner.js | 4 ++++ build/rollup_plugins.js | 6 +----- debug/csp-static.html | 36 ++++++++++++++++++++++++++++++++++++ package.json | 3 ++- rollup.config.csp.js | 32 ++++++++++++++++++++++++++++++++ rollup.config.js | 10 ++++------ 6 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 build/banner.js create mode 100644 debug/csp-static.html create mode 100644 rollup.config.csp.js diff --git a/build/banner.js b/build/banner.js new file mode 100644 index 00000000000..cb164daba95 --- /dev/null +++ b/build/banner.js @@ -0,0 +1,4 @@ +import fs from 'fs'; + +const version = JSON.parse(fs.readFileSync('package.json')).version; +export default `/* Mapbox GL JS is licensed under the 3-Clause BSD License. Full text of license: https://github.com/mapbox/mapbox-gl-js/blob/v${version}/LICENSE.txt */`; diff --git a/build/rollup_plugins.js b/build/rollup_plugins.js index 610232162fc..575f61055d6 100644 --- a/build/rollup_plugins.js +++ b/build/rollup_plugins.js @@ -9,14 +9,10 @@ import { terser } from 'rollup-plugin-terser'; import minifyStyleSpec from './rollup_plugin_minify_style_spec'; import { createFilter } from 'rollup-pluginutils'; -const {BUILD, MINIFY} = process.env; -const minified = MINIFY === 'true'; -const production = BUILD === 'production'; - // Common set of plugins/transformations shared across different rollup // builds (main mapboxgl bundle, style-spec package, benchmarks bundle) -export const plugins = () => [ +export const plugins = (minified, production) => [ flow(), minifyStyleSpec(), json(), diff --git a/debug/csp-static.html b/debug/csp-static.html new file mode 100644 index 00000000000..8e00ea66107 --- /dev/null +++ b/debug/csp-static.html @@ -0,0 +1,36 @@ + + + + Mapbox GL JS debug page + + + + + + + + + + +
+ + + + + + diff --git a/package.json b/package.json index a25e0845974..bd2db271441 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "watch-dev": "rollup -c --environment BUILD:dev --watch", "build-prod": "rollup -c --environment BUILD:production", "build-prod-min": "rollup -c --environment BUILD:production,MINIFY:true", + "build-csp": "rollup -c rollup.config.csp.js", "build-flow-types": "cp build/mapbox-gl.js.flow dist/mapbox-gl.js.flow && cp build/mapbox-gl.js.flow dist/mapbox-gl-dev.js.flow", "build-css": "postcss -o dist/mapbox-gl.css src/css/mapbox-gl.css", "build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/* dist/style-spec", @@ -140,7 +141,7 @@ "test-expressions": "build/run-node test/expression.test.js", "test-flow": "build/run-node build/generate-flow-typed-style-spec && flow .", "test-cov": "nyc --require=@mapbox/flow-remove-types/register --reporter=text-summary --reporter=lcov --cache run-s test-unit test-expressions test-query test-render", - "prepublishOnly": "run-s build-flow-types build-dev build-prod-min build-prod build-css build-style-spec test-build", + "prepublishOnly": "run-s build-flow-types build-dev build-prod-min build-prod build-csp build-css build-style-spec test-build", "codegen": "build/run-node build/generate-style-code.js && build/run-node build/generate-struct-arrays.js" }, "files": [ diff --git a/rollup.config.csp.js b/rollup.config.csp.js new file mode 100644 index 00000000000..b9860f7616d --- /dev/null +++ b/rollup.config.csp.js @@ -0,0 +1,32 @@ +import fs from 'fs'; +import {plugins} from './build/rollup_plugins'; +import banner from './build/banner'; + +// a config for generating a special GL JS bundle with static web worker code (in a separate file) +// https://github.com/mapbox/mapbox-gl-js/issues/6058 + +export default [{ + input: 'src/index.js', + output: { + name: 'mapboxgl', + file: 'dist/mapbox-gl.csp.js', + format: 'umd', + sourcemap: true, + indent: false, + banner + }, + treeshake: true, + plugins: plugins(true, true) +}, { + input: ['src/source/worker.js'], + output: { + name: 'mapboxgl', + file: 'dist/mapbox-gl.worker.js', + format: 'iife', + sourcemap: true, + indent: false, + banner + }, + treeshake: true, + plugins: plugins(true, true) +}]; diff --git a/rollup.config.js b/rollup.config.js index f6db3ebd732..b103700d52c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,8 @@ import fs from 'fs'; import sourcemaps from 'rollup-plugin-sourcemaps'; import {plugins} from './build/rollup_plugins'; +import banner from './build/banner'; -const version = JSON.parse(fs.readFileSync('package.json')).version; const {BUILD, MINIFY} = process.env; const minified = MINIFY === 'true'; const production = BUILD === 'production'; @@ -10,7 +10,7 @@ const outputFile = !production ? 'dist/mapbox-gl-dev.js' : minified ? 'dist/mapbox-gl.js' : 'dist/mapbox-gl-unminified.js'; -const config = [{ +export default [{ // First, use code splitting to bundle GL JS into three "chunks": // - rollup/build/index.js: the main module, plus all its dependencies not shared by the worker module // - rollup/build/worker.js: the worker module, plus all dependencies not shared by the main module @@ -28,7 +28,7 @@ const config = [{ chunkFileNames: 'shared.js' }, treeshake: production, - plugins: plugins() + plugins: plugins(minified, production) }, { // Next, bundle together the three "chunks" produced in the previous pass // into a single, final bundle. See rollup/bundle_prelude.js and @@ -41,7 +41,7 @@ const config = [{ sourcemap: production ? true : 'inline', indent: false, intro: fs.readFileSync(require.resolve('./rollup/bundle_prelude.js'), 'utf8'), - banner: `/* Mapbox GL JS is licensed under the 3-Clause BSD License. Full text of license: https://github.com/mapbox/mapbox-gl-js/blob/v${version}/LICENSE.txt */` + banner }, treeshake: false, plugins: [ @@ -50,5 +50,3 @@ const config = [{ sourcemaps() ], }]; - -export default config From 1484b78a0820b1a61c0b450354959250e90dc749 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 15 Mar 2019 17:23:08 +0200 Subject: [PATCH 2/6] update gitignore, remove leftover import --- .gitignore | 4 +--- rollup.config.csp.js | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5a628b3c2ba..5e2d75c9807 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ /rollup/build/ /docs/components/api.json /dist/ -/docs/pages/dist/mapbox-gl-dev.js -/docs/pages/dist/mapbox-gl.js -/docs/pages/dist/mapbox-gl-unminified.js +/docs/pages/dist/ *.js.map node_modules package-lock.json diff --git a/rollup.config.csp.js b/rollup.config.csp.js index b9860f7616d..bfb5db622b1 100644 --- a/rollup.config.csp.js +++ b/rollup.config.csp.js @@ -1,4 +1,3 @@ -import fs from 'fs'; import {plugins} from './build/rollup_plugins'; import banner from './build/banner'; From 79dcbe9d4f0fd377bcf16cb72a3dbd96f6b4e590 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 18 Mar 2019 12:46:09 +0200 Subject: [PATCH 3/6] use hyphen in csp/worker build names for consistency --- debug/csp-static.html | 4 ++-- rollup.config.csp.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debug/csp-static.html b/debug/csp-static.html index 8e00ea66107..112fd1107a0 100644 --- a/debug/csp-static.html +++ b/debug/csp-static.html @@ -17,11 +17,11 @@
- + + + `)} +

Mapbox CSS

From 2a0561676e16071c52f45e6aefc3692473c7e8b2 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 21 Mar 2019 10:24:07 +0200 Subject: [PATCH 5/6] rename mapbox-gl-worker to mapbox-gl-csp-worker --- debug/csp-static.html | 2 +- docs/components/quickstart.js | 4 ++-- rollup.config.csp.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debug/csp-static.html b/debug/csp-static.html index 112fd1107a0..952fff40b03 100644 --- a/debug/csp-static.html +++ b/debug/csp-static.html @@ -21,7 +21,7 @@ `)} diff --git a/rollup.config.csp.js b/rollup.config.csp.js index befaf7a49f4..4711bb6fcca 100644 --- a/rollup.config.csp.js +++ b/rollup.config.csp.js @@ -20,7 +20,7 @@ export default [{ input: ['src/source/worker.js'], output: { name: 'mapboxgl', - file: 'dist/mapbox-gl-worker.js', + file: 'dist/mapbox-gl-csp-worker.js', format: 'iife', sourcemap: true, indent: false, From e4130ec21fe401ef0d35743438645826985080e4 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 21 Mar 2019 10:39:35 +0200 Subject: [PATCH 6/6] nicer CSP build config --- rollup.config.csp.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/rollup.config.csp.js b/rollup.config.csp.js index 4711bb6fcca..8e1aee8e5e2 100644 --- a/rollup.config.csp.js +++ b/rollup.config.csp.js @@ -4,28 +4,21 @@ import banner from './build/banner'; // a config for generating a special GL JS bundle with static web worker code (in a separate file) // https://github.com/mapbox/mapbox-gl-js/issues/6058 -export default [{ - input: 'src/index.js', +const config = (input, file, format) => ({ + input, output: { name: 'mapboxgl', - file: 'dist/mapbox-gl-csp.js', - format: 'umd', + file, + format, sourcemap: true, indent: false, banner }, treeshake: true, plugins: plugins(true, true) -}, { - input: ['src/source/worker.js'], - output: { - name: 'mapboxgl', - file: 'dist/mapbox-gl-csp-worker.js', - format: 'iife', - sourcemap: true, - indent: false, - banner - }, - treeshake: true, - plugins: plugins(true, true) -}]; +}); + +export default [ + config('src/index.js', 'dist/mapbox-gl-csp.js', 'umd'), + config('src/source/worker.js', 'dist/mapbox-gl-csp-worker.js', 'iife') +];