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

Examples develop speedup #6139

Merged
merged 4 commits into from
Mar 11, 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
15 changes: 6 additions & 9 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
"main": "index.js",
"type": "module",
"scripts": {
"build": "cross-env NODE_ENV=production rollup -c",
"build:pre": "npm run -s build:metadata && npm run -s build:standalone && npm run -s build:sharing",
"build": "npm run -s build:pre && cross-env NODE_ENV=production rollup -c",
"build:pre": "npm run -s build:metadata && npm run -s build:sharing",
"build:metadata": "node ./scripts/metadata.mjs",
"build:sharing": "node ./scripts/sharing-html.mjs",
"build:standalone": "node ./scripts/standalone-html.mjs",
"build:thumbnails": "node ./scripts/thumbnails.mjs",
"rollup:watch": "cross-env NODE_ENV=development rollup -c -w",
"serve": "serve dist -l 5000 --no-request-logging --config ../serve.json",
"lint": "eslint . --ext .js,.ts,.tsx",
"watch": "cross-env concurrently --kill-others \"npm run rollup:watch\"",
"watch:debug": "cross-env ENGINE_PATH=../build/playcanvas.dbg.js npm run watch",
"watch:profiler": "cross-env ENGINE_PATH=../build/playcanvas.prf.js npm run watch",
"clean": "node ./scripts/clean.mjs",
"develop": "cross-env NODE_ENV=development concurrently --kill-others \"npm run watch\" \"npm run serve\"",
"clean": "node ./scripts/clean.mjs"
"lint": "eslint . --ext .js,.ts,.tsx",
"serve": "serve dist -l 5000 --no-request-logging --config ../serve.json",
"watch": "npm run -s build:pre && cross-env NODE_ENV=development rollup -c -w"
},
"eslintConfig": {
"root": true,
Expand Down
36 changes: 27 additions & 9 deletions examples/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import date from 'date-and-time';
import * as fs from 'node:fs';
import fse from 'fs-extra';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -89,13 +88,27 @@ function getEnginePathFiles() {
}

/**
* @param {string} name - The timer name.
* @returns {RollupPlugin} The plugin.
*/
function timestamp() {
function timeStart(name) {
return {
name: 'timestamp',
name: 'time-start',
buildStart() {
console.time(name);
}
};
}

/**
* @param {string} name - The timer name.
* @returns {RollupPlugin} The plugin.
*/
function timeEnd(name) {
return {
name: 'time-end',
writeBundle() {
console.log("\x1b[32m", "Finished at: " + date.format(new Date(), 'HH:mm:ss'));
console.timeEnd(name);
}
};
}
Expand Down Expand Up @@ -168,9 +181,9 @@ function buildAndWatchStandaloneExamples() {
}
},
generateBundle() {
const cmd = `cross-env NODE_ENV=${NODE_ENV} ENGINE_PATH=${ENGINE_PATH} npm run build:pre`;
console.log(cmd);
execSync(cmd, { stdio: 'inherit' });
const cmd = `cross-env NODE_ENV=${NODE_ENV} ENGINE_PATH=${ENGINE_PATH} npm run build:standalone`;
console.log("\x1b[32m%s\x1b[0m", cmd);
execSync(cmd);
}
};
}
Expand All @@ -180,6 +193,9 @@ function getEngineTargets() {
// Outputs: dist/iframe/playcanvas-extras.mjs
scriptTargetEs6('pcx', '../extras/index.js', 'dist/iframe/playcanvas-extras.mjs')
];
if (ENGINE_PATH) {
return targets;
}
if (NODE_ENV === 'production') {
// Outputs: dist/iframe/playcanvas.mjs
targets.push(buildTarget('release', 'es6', '../src/index.js', 'dist/iframe'));
Expand All @@ -202,9 +218,10 @@ export default [
file: `dist/copy.tmp`
},
plugins: [
timeStart('examples'),
buildAndWatchStandaloneExamples(),
copyStaticFiles(STATIC_FILES),
timestamp()
timeEnd('examples')
]
},
{
Expand All @@ -215,6 +232,7 @@ export default [
format: 'umd'
},
plugins: [
timeStart('site'),
alias({
entries: {
// define supported module overrides
Expand All @@ -231,7 +249,7 @@ export default [
preventAssignment: true
}),
(NODE_ENV === 'production' && terser()),
timestamp()
timeEnd('site')
]
},
...getEngineTargets()
Expand Down