From 3ed9e1443180b34386c18bb40a801761223c7ee7 Mon Sep 17 00:00:00 2001 From: nshen Date: Thu, 13 Jan 2022 18:05:08 +0800 Subject: [PATCH] clean code, add some comments, set chunkSizeWarningLimit to 5000 --- src/index.ts | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/index.ts b/src/index.ts index 84edf05..78794fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,21 +35,15 @@ function vitePluginCesium( isBuild = command === 'build'; if (c.base) { base = c.base; + if (base === '') base = './'; } - if (base === '') base = './'; - - CESIUM_BASE_URL = path.posix.join(base, CESIUM_BASE_URL); - if (c.build?.outDir) { outDir = c.build.outDir; } - const userConfig: UserConfig = { - build: { - assetsInlineLimit: 0, - chunkSizeWarningLimit: 4000 - } - }; + CESIUM_BASE_URL = path.posix.join(base, CESIUM_BASE_URL); + const userConfig: UserConfig = {}; if (!isBuild) { + // -----------dev----------- userConfig.optimizeDeps = { exclude: ['cesium'] }; @@ -57,19 +51,25 @@ function vitePluginCesium( CESIUM_BASE_URL: JSON.stringify(CESIUM_BASE_URL) }; } else { - userConfig.build = { - ...userConfig.build, - rollupOptions: { - output: { - intro: `window.CESIUM_BASE_URL = "${CESIUM_BASE_URL}";` + // -----------build------------ + if (rebuildCesium) { + // build 1) rebuild cesium library + userConfig.build = { + assetsInlineLimit: 0, + chunkSizeWarningLimit: 5000, + rollupOptions: { + output: { + intro: `window.CESIUM_BASE_URL = "${CESIUM_BASE_URL}";` + } + } + }; + } else { + // build 2) copy Cesium.js later + userConfig.build = { + rollupOptions: { + external: ['cesium'], + plugins: [externalGlobals({ cesium: 'Cesium' })] } - } - }; - - if (!rebuildCesium) { - userConfig.build!.rollupOptions = { - external: ['cesium'], - plugins: [externalGlobals({ cesium: 'Cesium' })] }; } }