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

Output treeshakeable module builds #4601

Merged
merged 6 commits into from
Sep 1, 2022
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
],
"license": "MIT",
"main": "build/playcanvas.js",
"module": "build/playcanvas.mjs",
"module": "build/playcanvas.mjs/index.js",
"types": "build/playcanvas.d.ts",
"sideEffects": false,
"bugs": {
"url": "https://github.com/playcanvas/engine/issues"
},
Expand Down Expand Up @@ -109,6 +110,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",
Expand Down
11 changes: 8 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ function buildTarget(buildType, moduleFormat) {
const banner = {
debug: ' (DEBUG PROFILER)',
release: '',
profiler: ' (PROFILER)'
profiler: ' (PROFILER)',
min: null
};

const outputPlugins = {
Expand Down Expand Up @@ -190,15 +191,16 @@ 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],
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
Expand Down Expand Up @@ -241,6 +243,7 @@ function buildTarget(buildType, moduleFormat) {
return {
input: 'src/index.js',
output: outputOptions,
preserveModules: moduleFormat === 'es6',
plugins: [
jscc(jsccOptions[buildType] || jsccOptions.release),
shaderChunks(buildType !== 'debug'),
Expand Down Expand Up @@ -291,6 +294,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) => {
Expand Down