From 575c29e7b669b0775286f20932e9dc2f24be4ab8 Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 11:44:29 +0000 Subject: [PATCH 1/6] Added ES6 bundle output --- rollup.config.mjs | 6 +++++- utils/rollup-build-target.mjs | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index 36c4a17961b..88c1b8a55ca 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -60,9 +60,13 @@ export default (args) => { ['release', 'debug', 'profiler', 'min'].forEach((t) => { ['es5', 'es6'].forEach((m) => { if (envTarget === null || envTarget === t || envTarget === m || envTarget === `${t}_${m}`) { - targets.push(buildTarget(t, m)); + const shouldBundle = m === 'es5'; + targets.push(buildTarget(t, m, 'src/index.js', 'build', shouldBundle)); } }); + + // Manually add an bundled es6 build + targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', true)); }); if (envTarget === null) { diff --git a/utils/rollup-build-target.mjs b/utils/rollup-build-target.mjs index cd471872344..594568b94b6 100644 --- a/utils/rollup-build-target.mjs +++ b/utils/rollup-build-target.mjs @@ -56,9 +56,10 @@ const stripFunctions = [ * @param {'es5'|'es6'} moduleFormat - The module format. * @param {string} input - Only used for Examples to change it to `../src/index.js`. * @param {string} [buildDir] - Only used for examples to change the output location. + * @param {Boolean} [shouldBundle] - Whether the target should be bundled. * @returns {RollupOptions} One rollup target. */ -function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = 'build') { +function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = 'build', shouldBundle = false) { const banner = { debug: ' (DEBUG)', release: ' (RELEASE)', @@ -104,7 +105,7 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = const outputExtension = { es5: '.js', - es6: '.mjs' + es6: shouldBundle ? '.esm.js' : '.mjs' }; /** @type {Record} */ @@ -125,11 +126,11 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = indent: '\t', sourcemap: sourceMap[buildType] || sourceMap.release, name: 'pc', - preserveModules: moduleFormat === 'es6' + preserveModules: !shouldBundle }; const loc = `${buildDir}/${outputFile[buildType]}${outputExtension[moduleFormat]}`; - outputOptions[moduleFormat === 'es6' ? 'dir' : 'file'] = loc; + outputOptions[shouldBundle ? 'file' : 'dir'] = loc; const sdkVersion = { _CURRENT_SDK_VERSION: version, @@ -168,6 +169,8 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = es6: moduleOptions(buildType) }; + console.log(babelOptions[moduleFormat]) + return { input, output: outputOptions, From 2d1ed3b050862653cfdf6195d858cd3eb783e986 Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 11:57:34 +0000 Subject: [PATCH 2/6] removed logging --- utils/rollup-build-target.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/rollup-build-target.mjs b/utils/rollup-build-target.mjs index 594568b94b6..9904f4f636c 100644 --- a/utils/rollup-build-target.mjs +++ b/utils/rollup-build-target.mjs @@ -169,8 +169,6 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = es6: moduleOptions(buildType) }; - console.log(babelOptions[moduleFormat]) - return { input, output: outputOptions, From 351f06e6912ec9a77fabedf4026828bfa7838ffd Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 12:30:30 +0000 Subject: [PATCH 3/6] renamed build outputs --- rollup.config.mjs | 9 ++++----- utils/rollup-build-target.mjs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index 88c1b8a55ca..c79a60a5c3f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -60,15 +60,14 @@ export default (args) => { ['release', 'debug', 'profiler', 'min'].forEach((t) => { ['es5', 'es6'].forEach((m) => { if (envTarget === null || envTarget === t || envTarget === m || envTarget === `${t}_${m}`) { - const shouldBundle = m === 'es5'; - targets.push(buildTarget(t, m, 'src/index.js', 'build', shouldBundle)); + targets.push(buildTarget(t, m, 'src/index.js', 'build', true)); } }); - - // Manually add an bundled es6 build - targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', true)); }); + // Manually add a single unbundled es6 build + targets.push(buildTarget('release', 'es6', 'src/index.js', 'build', false)); + if (envTarget === null) { // no targets specified, build them all buildTypes(); diff --git a/utils/rollup-build-target.mjs b/utils/rollup-build-target.mjs index 9904f4f636c..5c1cd095c76 100644 --- a/utils/rollup-build-target.mjs +++ b/utils/rollup-build-target.mjs @@ -105,7 +105,7 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir = const outputExtension = { es5: '.js', - es6: shouldBundle ? '.esm.js' : '.mjs' + es6: shouldBundle ? '.mjs' : '' }; /** @type {Record} */ From ac7f57a031c951fa1d9ee326443506fdc7ef86e7 Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 12:33:24 +0000 Subject: [PATCH 4/6] default package.json module now points to bundled build --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4e2419bc58..3364c1eac3e 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ ], "license": "MIT", "main": "build/playcanvas.js", - "module": "build/playcanvas.mjs/index.js", + "module": "build/playcanvas.mjs", "types": "build/playcanvas.d.ts", "sideEffects": false, "type": "module", From 295ed30671e2203fae665716af6e19dd171bef0f Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 14:00:17 +0000 Subject: [PATCH 5/6] Adds unbundled es6 variants --- rollup.config.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index c79a60a5c3f..aafa47ddd10 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -63,10 +63,12 @@ export default (args) => { targets.push(buildTarget(t, m, 'src/index.js', 'build', true)); } }); + + // Add an unbundled es6 build + targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', false)); + }); - // Manually add a single unbundled es6 build - targets.push(buildTarget('release', 'es6', 'src/index.js', 'build', false)); if (envTarget === null) { // no targets specified, build them all From ce0c76fe83100b863f2ad2be30ac348f8095b33c Mon Sep 17 00:00:00 2001 From: Mark Lundin Date: Wed, 21 Feb 2024 14:02:22 +0000 Subject: [PATCH 6/6] excluded min from unbundled es6 variant --- rollup.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index aafa47ddd10..0f947289c62 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -65,7 +65,7 @@ export default (args) => { }); // Add an unbundled es6 build - targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', false)); + if (t !== 'min') targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', false)); });