From 0b416e59217f7e82629036d2d1964cdddccde194 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 23 Aug 2022 16:46:01 +0100 Subject: [PATCH 1/3] build tree-shakable modules --- package.json | 3 ++- rollup.config.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6581c638965..81bdce6f30e 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ ], "license": "MIT", "main": "build/playcanvas.js", - "module": "build/playcanvas.mjs", + "module": "build/playcanvas.mjs/index.js", "types": "build/playcanvas.d.ts", "bugs": { "url": "https://github.com/playcanvas/engine/issues" @@ -109,6 +109,7 @@ "build:release": "rollup -c --environment target:release", "build:debug": "rollup -c --environment target:debug", "build:dts": "tsc src/index.js --outDir types --allowJs --declaration --emitDeclarationOnly", + "build:extras": "rollup -c --environment target:extras", "build:es5": "rollup -c --environment target:es5", "build:es6": "rollup -c --environment target:es6", "build:profiler": "rollup -c --environment target:profiler", diff --git a/rollup.config.js b/rollup.config.js index f7d6837a204..adae6118e87 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -192,13 +192,14 @@ function buildTarget(buildType, moduleFormat) { const outputOptions = { banner: getBanner(banner[buildType] || banner.release), plugins: outputPlugins[buildType || outputPlugins.release], - file: `${outputFile[buildType]}${outputExtension[moduleFormat]}`, format: outputFormat[moduleFormat], indent: '\t', sourcemap: sourceMap[buildType] || sourceMap.release, name: 'pc' }; + outputOptions[moduleFormat === 'es6' ? 'dir' : 'file'] = `${outputFile[buildType]}${outputExtension[moduleFormat]}`; + const sdkVersion = { _CURRENT_SDK_VERSION: version, _CURRENT_SDK_REVISION: revision @@ -241,6 +242,7 @@ function buildTarget(buildType, moduleFormat) { return { input: 'src/index.js', output: outputOptions, + preserveModules: moduleFormat === 'es6', plugins: [ jscc(jsccOptions[buildType] || jsccOptions.release), shaderChunks(buildType !== 'debug'), @@ -291,6 +293,8 @@ export default (args) => { const envTarget = process.env.target ? process.env.target.toLowerCase() : null; if (envTarget === 'types') { targets.push(target_types); + } else if (envTarget === 'extras') { + targets = targets.concat(target_extras); } else { ['release', 'debug', 'profiler', 'min'].forEach((t) => { ['es5', 'es6'].forEach((m) => { From 70acc8dcc058d17d07f0ef39d8de7576425f452e Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Thu, 25 Aug 2022 18:47:01 +0100 Subject: [PATCH 2/3] small --- package.json | 1 + rollup.config.js | 5 +++-- src/framework/app-options.js | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 81bdce6f30e..73d6489a6cc 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "main": "build/playcanvas.js", "module": "build/playcanvas.mjs/index.js", "types": "build/playcanvas.d.ts", + "sideEffects": false, "bugs": { "url": "https://github.com/playcanvas/engine/issues" }, diff --git a/rollup.config.js b/rollup.config.js index adae6118e87..e19a48142d2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -150,7 +150,8 @@ function buildTarget(buildType, moduleFormat) { const banner = { debug: ' (DEBUG PROFILER)', release: '', - profiler: ' (PROFILER)' + profiler: ' (PROFILER)', + min: null }; const outputPlugins = { @@ -190,7 +191,7 @@ function buildTarget(buildType, moduleFormat) { }; const outputOptions = { - banner: getBanner(banner[buildType] || banner.release), + banner: banner[buildType] && getBanner(banner[buildType] || banner.release), plugins: outputPlugins[buildType || outputPlugins.release], format: outputFormat[moduleFormat], indent: '\t', diff --git a/src/framework/app-options.js b/src/framework/app-options.js index ec328841440..327d00a90e9 100644 --- a/src/framework/app-options.js +++ b/src/framework/app-options.js @@ -15,35 +15,35 @@ class AppOptions { /** * Input handler for {@link ElementComponent}s. * - * @type {ElementInput} + * @type {ElementInput.constructor} */ elementInput; /** * Keyboard handler for input. * - * @type {Keyboard} + * @type {Keyboard.constructor} */ keyboard; /** * Mouse handler for input. * - * @type {Mouse} + * @typeof {Mouse} */ mouse; /** * TouchDevice handler for input. * - * @type {TouchDevice} + * @typeof {TouchDevice} */ touch; /** * Gamepad handler for input. * - * @type {GamePads} + * @typeof {GamePads} */ gamepads; @@ -71,49 +71,49 @@ class AppOptions { /** * The sound manager * - * @type {SoundManager} + * @typeof {SoundManager} */ soundManager; /** * The graphics device. * - * @type {GraphicsDevice} + * @typeof {GraphicsDevice} */ graphicsDevice; /** * The lightmapper. * - * @type {Lightmapper} + * @type {Lightmapper.constructor} */ lightmapper; /** * The BatchManager. * - * @type {BatchManager} + * @type {BatchManager.constructor} */ batchManager; /** * The XrManager. * - * @type {XrManager} + * @typeof {XrManager} */ xr; /** * The component systems the app requires. * - * @type {ComponentSystem[]} + * @typeof {ComponentSystem.constructor[]} */ componentSystems = []; /** * The resource handlers the app requires. * - * @type {ResourceHandler[]} + * @typeof {ResourceHandler.constructor[]} */ resourceHandlers = []; } From 73ee4d308c8fe5a796b43e5c101818a0bf2c6666 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Wed, 31 Aug 2022 10:52:42 +0100 Subject: [PATCH 3/3] revert --- src/framework/app-options.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/framework/app-options.js b/src/framework/app-options.js index 327d00a90e9..ec328841440 100644 --- a/src/framework/app-options.js +++ b/src/framework/app-options.js @@ -15,35 +15,35 @@ class AppOptions { /** * Input handler for {@link ElementComponent}s. * - * @type {ElementInput.constructor} + * @type {ElementInput} */ elementInput; /** * Keyboard handler for input. * - * @type {Keyboard.constructor} + * @type {Keyboard} */ keyboard; /** * Mouse handler for input. * - * @typeof {Mouse} + * @type {Mouse} */ mouse; /** * TouchDevice handler for input. * - * @typeof {TouchDevice} + * @type {TouchDevice} */ touch; /** * Gamepad handler for input. * - * @typeof {GamePads} + * @type {GamePads} */ gamepads; @@ -71,49 +71,49 @@ class AppOptions { /** * The sound manager * - * @typeof {SoundManager} + * @type {SoundManager} */ soundManager; /** * The graphics device. * - * @typeof {GraphicsDevice} + * @type {GraphicsDevice} */ graphicsDevice; /** * The lightmapper. * - * @type {Lightmapper.constructor} + * @type {Lightmapper} */ lightmapper; /** * The BatchManager. * - * @type {BatchManager.constructor} + * @type {BatchManager} */ batchManager; /** * The XrManager. * - * @typeof {XrManager} + * @type {XrManager} */ xr; /** * The component systems the app requires. * - * @typeof {ComponentSystem.constructor[]} + * @type {ComponentSystem[]} */ componentSystems = []; /** * The resource handlers the app requires. * - * @typeof {ResourceHandler.constructor[]} + * @type {ResourceHandler[]} */ resourceHandlers = []; }