enable expo experimental tree shaking

This commit is contained in:
Oleksii Bulenok
2026-08-11 13:57:38 +02:00
parent 64bc9672a8
commit d3de1795f7
3 changed files with 27 additions and 1 deletions
+4
View File
@@ -17,6 +17,10 @@ ENV CI=1
# use the pnpm version specified in package.json
ENV pnpm_config_pm_on_fail=download
# Metro's web export needs far more heap than Node's default (~1GB in the
# container), which crashes the bundle step with a V8 OOM.
ENV NODE_OPTIONS="--max-old-space-size=8192"
# The latest git hash of the preview branch on render.com
# https://render.com/docs/docker-secrets#environment-variables-in-docker-builds
ARG RENDER_GIT_COMMIT
+22
View File
@@ -1,3 +1,24 @@
/**
* React Compiler tags generated nodes with loc = Symbol(GeneratedSource),
* which breaks the structuredClone Metro performs on the AST when
* EXPO_UNSTABLE_TREE_SHAKING is enabled. Strip them after all other
* transforms have run.
*/
const stripSymbolLocs = () => ({
post(file) {
file.path.traverse({
enter(path) {
if (typeof path.node.loc === 'symbol') {
path.node.loc = undefined
}
},
})
if (typeof file.ast.program.loc === 'symbol') {
file.ast.program.loc = undefined
}
},
})
/**
* @param {import("@babel/core").ConfigAPI} api
* @returns {import("@babel/core").InputOptions}
@@ -45,6 +66,7 @@ module.exports = function (api) {
: []),
...(api.env('production') ? ['transform-remove-console'] : []),
stripSymbolLocs,
'react-native-worklets/plugin', // NOTE: this plugin MUST be last
],
}
+1 -1
View File
@@ -47,7 +47,7 @@
"web": "expo start --web",
"use-build-number": "./scripts/useBuildNumberEnv.sh",
"use-build-number-with-bump": "./scripts/useBuildNumberEnvWithBump.sh",
"build-web": "expo export --platform web --source-maps && node ./scripts/post-web-build.js",
"build-web": "EXPO_UNSTABLE_METRO_OPTIMIZE_GRAPH=1 EXPO_UNSTABLE_TREE_SHAKING=1 expo export --platform web --source-maps && node ./scripts/post-web-build.js",
"build-all": "pnpm intl:build && pnpm use-build-number-with-bump eas build --platform all",
"build-ios": "pnpm use-build-number-with-bump eas build -p ios",
"build-android": "pnpm use-build-number-with-bump eas build -p android",