mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
build: name the lazy Navara engine chunk navara-engine
chunkFileNames names the chunk holding src/globe/navara navara-engine-[hash].js; chunking is unchanged (manualChunks would pull modules shared with the Cesium entry into it and make the entry import it). The Cesium main chunk stays 2,849,217 B.
This commit is contained in:
1 parent
64d3297301
commit
8270172086
3 files changed
+56
-2
No files matched your search
@@ -43,3 +43,23 @@ export function navaraWorkerAssets({ assetsDir } = {}) {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const NAVARA_MODULE = /\/src\/globe\/navara\//;
|
||||
|
||||
/**
|
||||
* Rollup chunkFileNames: the lazy chunk holding the Navara engine
|
||||
* (src/globe/navara, with the Navara packages it pulls in) is named
|
||||
* `navara-engine-[hash].js`; every other chunk keeps Vite's default name.
|
||||
* Naming only (not manualChunks, which would pull modules shared with the
|
||||
* Cesium entry into the Navara chunk), so the chunking is unchanged.
|
||||
* @param {{ isEntry?: boolean, moduleIds?: string[] }} chunk
|
||||
* @returns {string}
|
||||
*/
|
||||
export function navaraChunkFileNames(chunk) {
|
||||
const navara =
|
||||
!chunk.isEntry &&
|
||||
(chunk.moduleIds ?? []).some((id) =>
|
||||
NAVARA_MODULE.test(id.replaceAll('\\', '/')),
|
||||
);
|
||||
return navara ? 'assets/navara-engine-[hash].js' : 'assets/[name]-[hash].js';
|
||||
}
|
||||
+6
-2
@@ -3,7 +3,7 @@ import cesium from 'vite-plugin-cesium';
|
||||
import { DEFAULT_ALLOWED_HOSTS, hostCheckPlugin } from './allowedHosts.js';
|
||||
import { embedFramingPlugin } from './embed-framing.js';
|
||||
import { panelBuildPlugin } from './panel.js';
|
||||
import { navaraWorkerAssets } from './navaraAssets.js';
|
||||
import { navaraChunkFileNames, navaraWorkerAssets } from './navaraAssets.js';
|
||||
|
||||
/**
|
||||
* Content-Security-Policy for every document the dev/preview server serves.
|
||||
@@ -130,7 +130,11 @@ export function createBrowserViteConfig({
|
||||
chunkSizeWarningLimit: 1500,
|
||||
// Build only: the wasm Navara's workers load by name (the Navara
|
||||
// engine is a separate chunk loaded on ?engine=navara).
|
||||
rollupOptions: { plugins: [navaraWorkerAssets()] },
|
||||
// The lazy chunk with the Navara engine is named navara-engine.
|
||||
rollupOptions: {
|
||||
plugins: [navaraWorkerAssets()],
|
||||
output: { chunkFileNames: navaraChunkFileNames },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -54,3 +54,33 @@ test('the browser build runs the Navara asset copy as a Rollup plugin', () => {
|
||||
);
|
||||
assert.equal(build.chunkSizeWarningLimit, 1500);
|
||||
});
|
||||
|
||||
test('the lazy chunk with the Navara engine is named navara-engine', async () => {
|
||||
const { navaraChunkFileNames } = await import('../../build/navaraAssets.js');
|
||||
for (const ids of [
|
||||
['/repo/src/globe/navara/index.js', '/repo/src/globe/navara/maps.js'],
|
||||
[
|
||||
'/repo/node_modules/@navaramap/three/dist/index.js',
|
||||
'/repo/src/globe/navara/index.js',
|
||||
],
|
||||
])
|
||||
assert.equal(
|
||||
navaraChunkFileNames({ isEntry: false, moduleIds: ids }),
|
||||
'assets/navara-engine-[hash].js',
|
||||
);
|
||||
for (const chunk of [
|
||||
{ isEntry: false, moduleIds: ['/repo/src/app/navaraMode.js'] },
|
||||
{ isEntry: false, moduleIds: ['/repo/src/globe/contract.js'] },
|
||||
// A package chunk split off by the bundler keeps its own name.
|
||||
{
|
||||
isEntry: false,
|
||||
moduleIds: ['/repo/node_modules/@navaramap/three/dist/spark.js'],
|
||||
},
|
||||
{ isEntry: true, moduleIds: ['/repo/src/globe/navara/index.js'] },
|
||||
{ isEntry: false },
|
||||
])
|
||||
assert.equal(navaraChunkFileNames(chunk), 'assets/[name]-[hash].js');
|
||||
const { build } = createBrowserViteConfig({});
|
||||
assert.equal(build.rollupOptions.output.chunkFileNames, navaraChunkFileNames);
|
||||
assert.equal(build.rollupOptions.output.manualChunks, undefined);
|
||||
});
|
||||
Reference in new issue
Block a user