From a10bc713f2347cf7ffd13887928a23db78ec9050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Tue, 2 Nov 2021 00:12:57 +0100 Subject: [PATCH] Configure additional sources displayed below map --- examples/external-map.html | 4 ++- examples/offscreen-canvas.html | 3 +- examples/templates/example.html | 11 ++++--- examples/webpack/example-builder.js | 45 ++++++++++++++++------------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/examples/external-map.html b/examples/external-map.html index 405fe44080..1cf5f4c030 100644 --- a/examples/external-map.html +++ b/examples/external-map.html @@ -5,7 +5,9 @@ shortdesc: Move a map to a seperate window. docs: > Move a map to a seperate window. tags: "external, window" +sources: + - resources/external-map-map.html ---
- + diff --git a/examples/offscreen-canvas.html b/examples/offscreen-canvas.html index 65438c4519..7218b3a78a 100644 --- a/examples/offscreen-canvas.html +++ b/examples/offscreen-canvas.html @@ -6,10 +6,11 @@ docs: > The map in this example is rendered in a web worker, using `OffscreenCanvas`. **Note:** This is currently only supported in Chrome and Edge. tags: "worker, offscreencanvas, vector-tiles" experimental: true +sources: + - offscreen-canvas.worker.js as worker.js cloak: - key: get_your_own_D6rA4zTHduk6KOKTXzGB value: Get your own API key at https://www.maptiler.com/cloud/ - ---
diff --git a/examples/templates/example.html b/examples/templates/example.html
index fdead5dd47..a9d2958068 100644
--- a/examples/templates/example.html
+++ b/examples/templates/example.html
@@ -211,13 +211,12 @@
 </html>
-{{#if worker.source}} -
-
worker.js
-
{{ worker.source }}
+{{#each extraSources}} +
+
{{./name}}
+
{{ ./source }}
-{{/if}} - +{{/each}}
package.json
{{ pkgJson }}
diff --git a/examples/webpack/example-builder.js b/examples/webpack/example-builder.js index c8efc6370a..55b307ab72 100644 --- a/examples/webpack/example-builder.js +++ b/examples/webpack/example-builder.js @@ -311,33 +311,38 @@ export default class ExampleBuilder { source: jsSource, }; - // check for worker js - const workerName = `${data.name}.worker.js`; - const workerPath = path.join(data.dir, workerName); - let workerSource; - try { - workerSource = await fse.readFile(workerPath, readOptions); - } catch (err) { - // pass - } - if (workerSource) { - workerSource = this.transformJsSource( - this.cloakSource(workerSource, data.cloak) + let jsSources = jsSource; + if (data.sources) { + data.extraSources = await Promise.all( + data.sources.map(async (fileName) => { + const as = fileName.split(/ +as +/); + fileName = as[0]; + const extraSourcePath = path.join(data.dir, fileName); + let source = await fse.readFile(extraSourcePath, readOptions); + let ext = fileName.match(/\.(\w+)$/)[1]; + if (ext === 'mjs') { + ext = 'js'; + } + if (ext === 'js') { + source = this.transformJsSource(source); + jsSources += '\n' + source; + } + source = this.cloakSource(source, data.cloak); + assets[fileName] = source; + return { + name: as[1] || fileName, + source: source, + type: ext, + }; + }) ); - data.worker = { - source: workerSource, - }; - assets[workerName] = workerSource; } const pkg = await getPackageInfo(); data.pkgJson = JSON.stringify( { name: data.name, - dependencies: getDependencies( - jsSource + (workerSource ? `\n${workerSource}` : ''), - pkg - ), + dependencies: getDependencies(jsSources, pkg), devDependencies: { parcel: '^2.0.0', },