Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Engine ESM build #6073

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions utils/rollup-build-target.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down Expand Up @@ -104,7 +105,7 @@ function buildTarget(buildType, moduleFormat, input = 'src/index.js', buildDir =

const outputExtension = {
es5: '.js',
es6: '.mjs'
es6: shouldBundle ? '.esm.js' : '.mjs'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current file extension scheme .js means UMD, shouldn't we keep .mjs? Maybe something like playcanvas.bundled.mjs

Copy link
Member Author

@marklundin marklundin Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's no easy answer here. playcanvas.mjs is the most obvious, and consistent with the UMD playcanvas.js build, but the .mjs suffix is currently pointing to a directory, and so I wonder if that build actually needs to be renamed

};

/** @type {Record<string, ModuleFormat>} */
Expand All @@ -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,
Expand Down
Loading