Skip to content

Commit

Permalink
feat: add support for preserving comments in code (#967)
Browse files Browse the repository at this point in the history
Summary:
Changelog:
* **[Feature]**: Preserve comments in unminified builds, while continuing to strip all comments from minified builds.

Add support for preserving comments in code. Useful for preserving `/*#__PURE__*/` annotations that aid tree shaking.

NOTE: In a future version of Metro, the default minifier options will change to align with the underlying minifier's default, e.g. `comments: 'some'` in Terser.

Pull Request resolved: #967

Test Plan:
Test case here: microsoft/rnx-kit#2365

|        |    Size |
| :----- | ------: |
| Before | 1567764 |
| After  | 1258413 |
| Diff   | -309351 |

Reviewed By: jacdebug

Differential Revision: D45223689

Pulled By: motiz88

fbshipit-source-id: 89c1e4050e67c3c34ec74015986827425b5fc76c
  • Loading branch information
tido64 authored and facebook-github-bot committed Apr 24, 2023
1 parent 48b6f5e commit 8d8f317
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Object {
},
"output": Object {
"ascii_only": true,
"comments": false,
"quote_style": 3,
"wrap_iife": true,
},
Expand Down Expand Up @@ -308,6 +309,7 @@ Object {
},
"output": Object {
"ascii_only": true,
"comments": false,
"quote_style": 3,
"wrap_iife": true,
},
Expand Down Expand Up @@ -485,6 +487,7 @@ Object {
},
"output": Object {
"ascii_only": true,
"comments": false,
"quote_style": 3,
"wrap_iife": true,
},
Expand Down Expand Up @@ -662,6 +665,7 @@ Object {
},
"output": Object {
"ascii_only": true,
"comments": false,
"quote_style": 3,
"wrap_iife": true,
},
Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
},
output: {
ascii_only: true,
comments: false,
quote_style: 3,
wrap_iife: true,
},
Expand Down
Loading

0 comments on commit 8d8f317

Please sign in to comment.