From ae7581d6a6020cc967253c3103febe82661f3d50 Mon Sep 17 00:00:00 2001 From: Evyatar Date: Wed, 2 Aug 2023 23:54:00 +0300 Subject: [PATCH] vx: separate dev and prod builds --- packages/vest/package.json | 60 +++++++++++++++--------------- vx/config/rollup/rollup.config.cjs | 35 +++++++++-------- vx/opts.js | 1 + vx/scripts/build/buildPackage.js | 20 ++++++++++ 4 files changed, 68 insertions(+), 48 deletions(-) diff --git a/packages/vest/package.json b/packages/vest/package.json index 1e49a51eb..dc092246c 100644 --- a/packages/vest/package.json +++ b/packages/vest/package.json @@ -25,36 +25,6 @@ "vestjs-runtime": "^0.0.1" }, "exports": { - "./suiteSerializer": { - "production": { - "types": "./types/suiteSerializer.d.ts", - "browser": "./dist/es/suiteSerializer.production.js", - "umd": "./dist/umd/suiteSerializer.production.js", - "import": "./dist/es/suiteSerializer.production.js", - "require": "./dist/cjs/suiteSerializer.production.js", - "node": "./dist/cjs/suiteSerializer.production.js", - "module": "./dist/es/suiteSerializer.production.js", - "default": "./dist/cjs/suiteSerializer.production.js" - }, - "development": { - "types": "./types/suiteSerializer.d.ts", - "browser": "./dist/es/suiteSerializer.development.js", - "umd": "./dist/umd/suiteSerializer.development.js", - "import": "./dist/es/suiteSerializer.development.js", - "require": "./dist/cjs/suiteSerializer.development.js", - "node": "./dist/cjs/suiteSerializer.development.js", - "module": "./dist/es/suiteSerializer.development.js", - "default": "./dist/cjs/suiteSerializer.development.js" - }, - "types": "./types/suiteSerializer.d.ts", - "browser": "./dist/es/suiteSerializer.production.js", - "umd": "./dist/umd/suiteSerializer.production.js", - "import": "./dist/es/suiteSerializer.production.js", - "require": "./dist/cjs/suiteSerializer.production.js", - "node": "./dist/cjs/suiteSerializer.production.js", - "module": "./dist/es/suiteSerializer.production.js", - "default": "./dist/cjs/suiteSerializer.production.js" - }, "./promisify": { "production": { "types": "./types/promisify.d.ts", @@ -295,6 +265,36 @@ "module": "./dist/es/classnames.production.js", "default": "./dist/cjs/classnames.production.js" }, + "./SuiteSerializer": { + "production": { + "types": "./types/SuiteSerializer.d.ts", + "browser": "./dist/es/SuiteSerializer.production.js", + "umd": "./dist/umd/SuiteSerializer.production.js", + "import": "./dist/es/SuiteSerializer.production.js", + "require": "./dist/cjs/SuiteSerializer.production.js", + "node": "./dist/cjs/SuiteSerializer.production.js", + "module": "./dist/es/SuiteSerializer.production.js", + "default": "./dist/cjs/SuiteSerializer.production.js" + }, + "development": { + "types": "./types/SuiteSerializer.d.ts", + "browser": "./dist/es/SuiteSerializer.development.js", + "umd": "./dist/umd/SuiteSerializer.development.js", + "import": "./dist/es/SuiteSerializer.development.js", + "require": "./dist/cjs/SuiteSerializer.development.js", + "node": "./dist/cjs/SuiteSerializer.development.js", + "module": "./dist/es/SuiteSerializer.development.js", + "default": "./dist/cjs/SuiteSerializer.development.js" + }, + "types": "./types/SuiteSerializer.d.ts", + "browser": "./dist/es/SuiteSerializer.production.js", + "umd": "./dist/umd/SuiteSerializer.production.js", + "import": "./dist/es/SuiteSerializer.production.js", + "require": "./dist/cjs/SuiteSerializer.production.js", + "node": "./dist/cjs/SuiteSerializer.production.js", + "module": "./dist/es/SuiteSerializer.production.js", + "default": "./dist/cjs/SuiteSerializer.production.js" + }, ".": { "development": { "types": "./types/vest.d.ts", diff --git a/vx/config/rollup/rollup.config.cjs b/vx/config/rollup/rollup.config.cjs index adad371f2..a4c667939 100644 --- a/vx/config/rollup/rollup.config.cjs +++ b/vx/config/rollup/rollup.config.cjs @@ -23,30 +23,29 @@ module.exports = commandLineArgs => { const { [opts.vx_config.VX_ROLLUP_FAST_BUILD]: fastBuild, [opts.vx_config.VX_ROLLUP_BUILD_ENTRY]: buildEntry, + [opts.vx_config.VX_ROLLUP_ENV]: env, } = commandLineArgs; const fast = JSON.parse(fastBuild); return cleanupConfig( - concatTruthy(opts.env.PRODUCTION, !fast && opts.env.DEVELOPMENT).map( - env => { - const packageName = usePackage(); - - switch (buildEntry) { - case opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN: - return genBaseConfig({ env, packageName }); - case opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS: - return genExportsConfig(packageName, env); - default: - throw new Error( - `Invalid build entry: ${buildEntry}. Must be one of: ${[ - opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN, - opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS, - ].join(', ')}` - ); - } + concatTruthy(env).map(env => { + const packageName = usePackage(); + + switch (buildEntry) { + case opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN: + return genBaseConfig({ env, packageName }); + case opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS: + return genExportsConfig(packageName, env); + default: + throw new Error( + `Invalid build entry: ${buildEntry}. Must be one of: ${[ + opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN, + opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS, + ].join(', ')}` + ); } - ) + }) ); }; diff --git a/vx/opts.js b/vx/opts.js index 483842152..659b76692 100644 --- a/vx/opts.js +++ b/vx/opts.js @@ -45,6 +45,7 @@ module.exports = { VX_ROLLUP_BUILD_ENTRY: 'configbuildEntry', VX_ROLLUP_BUILD_ENTRY_EXPORTS: 'EXPORTS', VX_ROLLUP_BUILD_ENTRY_MAIN: 'MAIN', + VX_ROLLUP_ENV: 'configEnv', VX_ROLLUP_FAST_BUILD: 'configfastBuild', }, }; diff --git a/vx/scripts/build/buildPackage.js b/vx/scripts/build/buildPackage.js index be9bc6ddb..7a4326516 100644 --- a/vx/scripts/build/buildPackage.js +++ b/vx/scripts/build/buildPackage.js @@ -31,8 +31,17 @@ function buildPackage(options = {}) { buildRollup({ ...baseOptions, buildEntry: opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN, + env: opts.env.PRODUCTION, }); + if (!options.fastBuild) { + buildRollup({ + ...baseOptions, + buildEntry: opts.vx_config.VX_ROLLUP_BUILD_ENTRY_MAIN, + env: opts.env.DEVELOPMENT, + }); + } + const packageExportsPath = vxPath.packageSrcExports(name); // BUILD EXPORTS @@ -40,7 +49,16 @@ function buildPackage(options = {}) { buildRollup({ ...baseOptions, buildEntry: opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS, + env: opts.env.PRODUCTION, }); + + if (!options.fastBuild) { + buildRollup({ + ...baseOptions, + buildEntry: opts.vx_config.VX_ROLLUP_BUILD_ENTRY_EXPORTS, + env: opts.env.DEVELOPMENT, + }); + } } delete process.env.VX_PACKAGE_NAME; @@ -51,12 +69,14 @@ function buildRollup({ format = [], fastBuild = false, buildEntry, + env = opts.env.PRODUCTION, }) { exec([ `yarn rollup -c`, vxPath.ROLLUP_CONFIG_PATH, cliOptions, format.length && `--format=${format}`, + `--${opts.vx_config.VX_ROLLUP_ENV}=${env}`, `--${opts.vx_config.VX_ROLLUP_FAST_BUILD}=${fastBuild}`, `--${opts.vx_config.VX_ROLLUP_BUILD_ENTRY}=${buildEntry}`, ]);