Skip to content

Commit

Permalink
Examples develop speedup (#6139)
Browse files Browse the repository at this point in the history
* changed rollup to only rebuild standalone files not entire metadata

* removed old watch commands; added prebuild before watch and build commands
  • Loading branch information
kpal81xd authored Mar 11, 2024
1 parent dcb7793 commit d438df5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
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

0 comments on commit d438df5

Please sign in to comment.