From e0354b61fdb9848f877af160dc4183626b5ca2e6 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 13 Jun 2024 14:44:21 +0800 Subject: [PATCH] Build JS module only in development mode (#62398) Co-authored-by: kevin940726 Co-authored-by: gziolo --- bin/packages/build-worker.js | 12 ++++++++---- package.json | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/packages/build-worker.js b/bin/packages/build-worker.js index 3f1512ef0feb78..8033976c045317 100644 --- a/bin/packages/build-worker.js +++ b/bin/packages/build-worker.js @@ -13,6 +13,8 @@ const postcss = require( 'postcss' ); */ const getBabelConfig = require( './get-babel-config' ); +const isDev = process.env.NODE_ENV === 'development'; + /** * Path to packages directory. * @@ -27,10 +29,12 @@ const PACKAGES_DIR = path * * @type {Object} */ -const JS_ENVIRONMENTS = { - main: 'build', - module: 'build-module', -}; +const JS_ENVIRONMENTS = isDev + ? { module: 'build-module' } + : { + main: 'build', + module: 'build-module', + }; /** * Promisified fs.readFile. diff --git a/package.json b/package.json index ca8ebb89876a60..6e214c0b738bbe 100644 --- a/package.json +++ b/package.json @@ -274,8 +274,8 @@ "build:plugin-zip": "bash ./bin/build-plugin-zip.sh", "clean:package-types": "tsc --build --clean && rimraf \"./packages/*/build-types\"", "clean:packages": "rimraf \"./packages/*/@(build|build-module|build-style)\"", - "dev": "npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"", - "dev:packages": "concurrently \"node ./bin/packages/watch.js\" \"tsc --build --watch\"", + "dev": "cross-env NODE_ENV=development npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"", + "dev:packages": "cross-env NODE_ENV=development concurrently \"node ./bin/packages/watch.js\" \"tsc --build --watch\"", "distclean": "git clean --force -d -X", "docs:api-ref": "node ./bin/api-docs/update-api-docs.js", "docs:blocks": "node ./bin/api-docs/gen-block-lib-list.js",