Import React from import map (#32335)
Closes #24863 Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
14494fb148
commit
293333056f
3 changed files with 20 additions and 2 deletions
|
@ -3,7 +3,8 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm build:clean && rollup --config",
|
"build": "pnpm build:clean && rollup --config && pnpm build:rewrite-import",
|
||||||
|
"build:rewrite-import": "node scripts/rewrite-imports.js",
|
||||||
"build:clean": "shx rm -rf vendor"
|
"build:clean": "shx rm -rf vendor"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -12,7 +12,7 @@ const plugins = [
|
||||||
preventAssignment: true,
|
preventAssignment: true,
|
||||||
// React depends on process.env.NODE_ENV to determine which code to include for production.
|
// React depends on process.env.NODE_ENV to determine which code to include for production.
|
||||||
// This ensures that no additional code meant for development is included in the build.
|
// This ensures that no additional code meant for development is included in the build.
|
||||||
"process.env.NODE_ENV": JSON.stringify("production"),
|
"process.env.NODE_ENV": '"production"',
|
||||||
}),
|
}),
|
||||||
terser(),
|
terser(),
|
||||||
];
|
];
|
||||||
|
|
17
themes/scripts/rewrite-imports.js
Normal file
17
themes/scripts/rewrite-imports.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
const targetDir = "target/classes/theme/keycloak/common/resources/vendor";
|
||||||
|
|
||||||
|
replaceContents(
|
||||||
|
path.join(targetDir, "react/react-jsx-runtime.production.min.js"),
|
||||||
|
'"./react.production.min.js"',
|
||||||
|
'"react"',
|
||||||
|
);
|
||||||
|
|
||||||
|
async function replaceContents(filePath, search, replace) {
|
||||||
|
const file = await fs.readFile(filePath, "utf8");
|
||||||
|
const newFile = file.replace(search, replace);
|
||||||
|
|
||||||
|
await fs.writeFile(filePath, newFile);
|
||||||
|
}
|
Loading…
Reference in a new issue