Skip to content

Commit 6351004

Browse files
authored
chore(build): strip console.* from production bundles (#257)
Resolves: #256 ## PR Objective Make logging a dev-only affair: every `console.*` call (including `console.error`) is stripped from production bundles at build time, while development and test behavior stays exactly as it is today. The app has no crash reporting that would consume production logs, so in release builds they only added bundle weight and leaked internal error messages into system logs (`adb logcat` / os_log). ## What changed? * **`babel-plugin-transform-remove-console`** added as a devDependency. * **`babel.config.js`:** new `env.production` block enabling the plugin. Metro sets `BABEL_ENV=production` for release bundles, so the transform applies only there — dev bundles and Jest (`test` env) are untouched. * **No `exclude` list on purpose:** `console.error` is stripped too. If we ever add crash reporting, the follow-up should route errors through a logger instead of re-keeping raw `console.error`. * **Zero call-site changes:** all ~37 existing `console.warn` / `console.error` calls across stores, hooks, and components stay as they are — the transform removes them from the release output. ## Verification * Ran a sample module through the project's real Babel config in both env modes: * `development` → all of `log` / `warn` / `error` / `info` / `debug` kept, * `production` → all stripped. * Full Jest suite and ESLint pass. > **Note for local release builds:** reset the Metro cache once (`yarn start --reset-cache`) so the new transform takes effect.
1 parent 7ed1e5a commit 6351004

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ module.exports = function (api) {
1818
},
1919
],
2020
],
21+
env: {
22+
// Strip every console.* call (error included — there is no crash
23+
// reporting to feed) from release bundles; dev and test keep them.
24+
production: {
25+
plugins: ['transform-remove-console'],
26+
},
27+
},
2128
};
2229
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"@testing-library/react-native": "^13.3.3",
119119
"@types/jest": "29.5.14",
120120
"@types/react": "~19.2.10",
121+
"babel-plugin-transform-remove-console": "^6.9.4",
121122
"eslint": "^9",
122123
"eslint-config-prettier": "^10.1.8",
123124
"eslint-plugin-prettier": "^5.5.5",

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,6 +4290,13 @@ __metadata:
42904290
languageName: node
42914291
linkType: hard
42924292

4293+
"babel-plugin-transform-remove-console@npm:^6.9.4":
4294+
version: 6.9.4
4295+
resolution: "babel-plugin-transform-remove-console@npm:6.9.4"
4296+
checksum: 1123c3816c6f89c064752199c8796f30265d937f5d8e1e43d3837f1c0e87ed0e6bbd0afa6117ce021c8b93ec1de7154e158674bb22331c7ed6609d10121359df
4297+
languageName: node
4298+
linkType: hard
4299+
42934300
"babel-preset-current-node-syntax@npm:^1.0.0":
42944301
version: 1.2.0
42954302
resolution: "babel-preset-current-node-syntax@npm:1.2.0"
@@ -10287,6 +10294,7 @@ __metadata:
1028710294
"@testing-library/react-native": ^13.3.3
1028810295
"@types/jest": 29.5.14
1028910296
"@types/react": ~19.2.10
10297+
babel-plugin-transform-remove-console: ^6.9.4
1029010298
eslint: ^9
1029110299
eslint-config-prettier: ^10.1.8
1029210300
eslint-plugin-prettier: ^5.5.5

0 commit comments

Comments
 (0)