Skip to content

Commit 2f085d9

Browse files
georginahalpernGeorgina
andauthored
Remove dev step from tooling builds (reducing memory pressure) and copy the minified file to a max.js file for backwards compat (#16760)
Originally our build commands for our tools were running both dev and prod, outputted an unminified max.js file during CI. This impacted memory usage during build and is not necessary for debugging since we offer source maps. This PR removes the dev step from our builds, so we won't be outputting the unminified max.js files anymore. But in order to preserve backwards compatibility for users who may have been referencing the .max.js file directly, we now copy the minified file to a .max.js file after the build is complete. This plugin will only run if the `minToMax` option is set to true in the webpack configuration. --------- Co-authored-by: Georgina <[email protected]>
1 parent f3307a7 commit 2f085d9

File tree

25 files changed

+67
-27
lines changed

25 files changed

+67
-27
lines changed

packages/dev/buildTools/src/webpackTools.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import transformer from "./pathTransform.js";
44
import type { BuildType, DevPackageName, UMDPackageName } from "./packageMapping.js";
55
import { getPackageMappingByDevName, getPublicPackageName, isValidDevPackageName, umdPackageMapping } from "./packageMapping.js";
66
import * as path from "path";
7-
import { camelize } from "./utils.js";
8-
import type { RuleSetRule, Configuration } from "webpack";
7+
import { camelize, copyFile } from "./utils.js";
8+
import type { RuleSetRule, Configuration, Compiler } from "webpack";
99

1010
// eslint-disable-next-line @typescript-eslint/naming-convention
1111
export const externalsFunction = (excludePackages: string[] = [], type: BuildType = "umd") => {
@@ -220,6 +220,33 @@ export const commonDevWebpackConfiguration = (
220220
};
221221
};
222222

223+
/**
224+
* Originally our build commands for our tools were running both dev and prod, outputted an unminified max.js file during CI. This impacted memory usage during
225+
* build and is not necessary for debugging since we offer source maps. We have since removed the dev step from our builds, but in order to preserve
226+
* backwards compatibility for users who may have been referencing the .max.js file directly, we now copy the minified file to a .max.js file
227+
* after the build is complete. This plugin will only run if the `copyMinToMax` option is set to true in the webpack configuration.
228+
*/
229+
class CopyMinToMaxWebpackPlugin {
230+
apply(compiler: Compiler) {
231+
compiler.hooks.done.tap("CopyToMax", (stats) => {
232+
const outputPath = stats.compilation.outputOptions.path;
233+
const file = stats.compilation.outputOptions.filename?.toString();
234+
if (outputPath && file) {
235+
const from = path.join(outputPath, file);
236+
let to;
237+
if (file.includes(".min.js")) {
238+
// if maxMode is false, the minified file will have .min.js suffix and the max file will have no suffix
239+
to = path.join(outputPath, file.replace(/\.min\.js$/, ".js"));
240+
} else {
241+
// if maxMode is true, the minified file will have no suffix and the max file will have max.js suffix
242+
to = path.join(outputPath, file.replace(/\.js$/, ".max.js"));
243+
}
244+
copyFile(from, to);
245+
}
246+
});
247+
}
248+
}
249+
223250
// eslint-disable-next-line @typescript-eslint/naming-convention
224251
export const commonUMDWebpackConfiguration = (options: {
225252
entryPoints?: { [name: string]: string };
@@ -235,6 +262,7 @@ export const commonUMDWebpackConfiguration = (options: {
235262
es6Mode?: boolean;
236263
maxMode?: boolean; // if true filename will have .max for the dev version and nothing for the prod version
237264
extraExternals?: Configuration["externals"]; // see https://webpack.js.org/configuration/externals/#combining-syntaxes
265+
minToMax?: boolean; // if true, will copy the minified file to a file with max.js suffix. This is for back-compat reasons in case users reference .max.js output directly. For debugging purposes, we expose the sourcemap
238266
}) => {
239267
const packageMapping = getPackageMappingByDevName(options.devPackageName);
240268
const packageName = getPublicPackageName(options.es6Mode ? packageMapping.es6 : packageMapping.umd);
@@ -248,6 +276,7 @@ export const commonUMDWebpackConfiguration = (options: {
248276
entry: options.entryPoints ?? "./src/index.ts",
249277
devtool: options.mode === "production" ? "source-map" : "inline-cheap-module-source-map",
250278
mode: options.mode || "development",
279+
plugins: options.minToMax && options.mode === "production" ? [new CopyMinToMaxWebpackPlugin()] : [],
251280
output: {
252281
path: options.outputPath || path.resolve("./dist"),
253282
filename: (typeof options.overrideFilename === "function" && options.overrideFilename) || filename,
@@ -277,7 +306,6 @@ export const commonUMDWebpackConfiguration = (options: {
277306
tsOptions: {
278307
getCustomTransformers: (_program: ts.Program) => {
279308
// webpack program
280-
console.log("generating transformers...");
281309
return {
282310
after: [
283311
transformer(_program, {

packages/public/@babylonjs/gui-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license.md"
1212
],
1313
"scripts": {
14-
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run build:declaration",
14+
"build": "npm run clean && npm run build:prod && npm run build:declaration",
1515
"build:dev": "webpack --env development",
1616
"build:prod": "webpack --env production",
1717
"build:declaration": "build-tools -c pud --config ./config.json",

packages/public/@babylonjs/gui-editor/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = (env) => {
99
namespace: "GUIEDITOR",
1010
es6Mode: true,
1111
maxMode: true,
12+
minToMax: true,
1213
alias: {
1314
"shared-ui-components": path.resolve("../../../dev/sharedUiComponents/dist"),
1415
},

packages/public/@babylonjs/inspector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license.md"
1212
],
1313
"scripts": {
14-
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run build:declaration",
14+
"build": "npm run clean && npm run build:prod && npm run build:declaration",
1515
"build:dev": "webpack --env development",
1616
"build:prod": "webpack --env production",
1717
"build:declaration": "build-tools -c pud --config ./config.json",

packages/public/@babylonjs/inspector/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = (env) => {
99
namespace: "INSPECTOR",
1010
es6Mode: true,
1111
maxMode: true,
12+
minToMax: true,
1213
alias: {
1314
"shared-ui-components": path.resolve("../../../dev/sharedUiComponents/dist"),
1415
},

packages/public/@babylonjs/node-editor/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "@babylonjs/node-editor",
33
"version": "8.13.0",
4-
"main": "dist/babylon.nodeEditor.max.js",
5-
"module": "dist/babylon.nodeEditor.max.js",
6-
"esnext": "dist/babylon.nodeEditor.max.js",
4+
"main": "dist/babylon.nodeEditor.js",
5+
"module": "dist/babylon.nodeEditor.js",
6+
"esnext": "dist/babylon.nodeEditor.js",
77
"typings": "dist/babylon.nodeEditor.module.d.ts",
88
"files": [
99
"dist/**/*.*",
1010
"readme.md",
1111
"license.md"
1212
],
1313
"scripts": {
14-
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run build:declaration",
14+
"build": "npm run clean && npm run build:prod && npm run build:declaration",
1515
"build:dev": "webpack --env development",
1616
"build:prod": "webpack --env production",
1717
"build:declaration": "build-tools -c pud --config ./config.json",

packages/public/@babylonjs/node-editor/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = (env) => {
99
namespace: "NODEEDITOR",
1010
es6Mode: true,
1111
maxMode: true,
12+
minToMax: true,
1213
alias: {
1314
"shared-ui-components": path.resolve("../../../dev/sharedUiComponents/dist"),
1415
},

packages/public/@babylonjs/node-geometry-editor/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "@babylonjs/node-geometry-editor",
33
"version": "8.13.0",
4-
"main": "dist/babylon.nodeGeometryEditor.max.js",
5-
"module": "dist/babylon.nodeGeometryEditor.max.js",
6-
"esnext": "dist/babylon.nodeGeometryEditor.max.js",
4+
"main": "dist/babylon.nodeGeometryEditor.js",
5+
"module": "dist/babylon.nodeGeometryEditor.js",
6+
"esnext": "dist/babylon.nodeGeometryEditor.js",
77
"typings": "dist/babylon.nodeGeometryEditor.module.d.ts",
88
"files": [
99
"dist/**/*.*",
1010
"readme.md",
1111
"license.md"
1212
],
1313
"scripts": {
14-
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run build:declaration",
14+
"build": "npm run clean && npm run build:prod && npm run build:declaration",
1515
"build:dev": "webpack --env development",
1616
"build:prod": "webpack --env production",
1717
"build:declaration": "build-tools -c pud --config ./config.json",

packages/public/@babylonjs/node-geometry-editor/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = (env) => {
99
namespace: "NODEGEOMETRYEDITOR",
1010
es6Mode: true,
1111
maxMode: true,
12+
minToMax: true,
1213
alias: {
1314
"shared-ui-components": path.resolve("../../../dev/sharedUiComponents/dist"),
1415
},

packages/public/@babylonjs/node-particle-editor/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "@babylonjs/node-particle-editor",
33
"version": "8.12.0",
4-
"main": "dist/babylon.nodeParticleEditor.max.js",
5-
"module": "dist/babylon.nodeParticleEditor.max.js",
6-
"esnext": "dist/babylon.nodeParticleEditor.max.js",
4+
"main": "dist/babylon.nodeParticleEditor.js",
5+
"module": "dist/babylon.nodeParticleEditor.js",
6+
"esnext": "dist/babylon.nodeParticleEditor.js",
77
"typings": "dist/babylon.nodeParticleEditor.module.d.ts",
88
"files": [
99
"dist/**/*.*",
1010
"readme.md",
1111
"license.md"
1212
],
1313
"scripts": {
14-
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run build:declaration",
14+
"build": "npm run clean && npm run build:prod && npm run build:declaration",
1515
"build:dev": "webpack --env development",
1616
"build:prod": "webpack --env production",
1717
"build:declaration": "build-tools -c pud --config ./config.json",

0 commit comments

Comments
 (0)