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 all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ 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));
targets.push(buildTarget(t, m, 'src/index.js', 'build', true));
}
});

// Add an unbundled es6 build
if (t !== 'min') targets.push(buildTarget(t, 'es6', 'src/index.js', 'build', false));

});


if (envTarget === null) {
// no targets specified, build them all
buildTypes();
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 ? '.mjs' : ''
};

/** @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