Skip to content

Commit 7a46505

Browse files
committed
fix(minify): only preserve some comments and annotations by default
1 parent 7bf3757 commit 7a46505

File tree

18 files changed

+122
-55
lines changed

18 files changed

+122
-55
lines changed

packages/core/src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ export function composeMinifyConfig(config: LibConfig): RsbuildConfig {
325325
toplevel: format !== 'mf',
326326
},
327327
format: {
328-
comments: 'all',
328+
comments: 'some',
329+
preserve_annotations: true,
329330
},
330331
},
331332
},

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
9090
"unused": true,
9191
},
9292
"format": {
93-
"comments": "all",
93+
"comments": "some",
94+
"preserve_annotations": true,
9495
},
9596
"mangle": false,
9697
"minify": false,
@@ -327,7 +328,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
327328
"unused": true,
328329
},
329330
"format": {
330-
"comments": "all",
331+
"comments": "some",
332+
"preserve_annotations": true,
331333
},
332334
"mangle": false,
333335
"minify": false,
@@ -557,7 +559,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
557559
"unused": true,
558560
},
559561
"format": {
560-
"comments": "all",
562+
"comments": "some",
563+
"preserve_annotations": true,
561564
},
562565
"mangle": false,
563566
"minify": false,

packages/core/tests/config.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ describe('minify', () => {
331331
"unused": true,
332332
},
333333
"format": {
334-
"comments": "all",
334+
"comments": "some",
335+
"preserve_annotations": true,
335336
},
336337
"mangle": false,
337338
"minify": false,

pnpm-lock.yaml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/asset/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
2424
]
2525
})
2626
});
27-
/* ESM default export */ const logoreact = SvgLogo;
27+
const logoreact = SvgLogo;
2828
console.log(logoreact);
2929
"
3030
`;
@@ -53,7 +53,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
5353
]
5454
})
5555
});
56-
/* ESM default export */ const logoreact = SvgLogo;
56+
const logoreact = SvgLogo;
5757
console.log(logoreact);
5858
"
5959
`;

tests/integration/bundle-false/__snapshots__/index.test.ts.snap

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
2424
]
2525
})
2626
});
27-
/* ESM default export */ const logoreact = SvgLogo;
28-
/* ESM default export */ const src_rslib_entry_ = logoreact;
27+
const logoreact = SvgLogo;
28+
const src_rslib_entry_ = logoreact;
2929
export { src_rslib_entry_ as default };
3030
"
3131
`;
3232

3333
exports[`svgr in bundleless 2`] = `
3434
""use strict";
35-
// The require scope
3635
var __webpack_require__ = {};
37-
/************************************************************************/ // webpack/runtime/define_property_getters
3836
(()=>{
3937
__webpack_require__.d = function(exports1, definition) {
4038
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -43,15 +41,12 @@ var __webpack_require__ = {};
4341
});
4442
};
4543
})();
46-
// webpack/runtime/has_own_property
4744
(()=>{
4845
__webpack_require__.o = function(obj, prop) {
4946
return Object.prototype.hasOwnProperty.call(obj, prop);
5047
};
5148
})();
52-
// webpack/runtime/make_namespace_object
5349
(()=>{
54-
// define __esModule on exports
5550
__webpack_require__.r = function(exports1) {
5651
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
5752
value: 'Module'
@@ -61,12 +56,10 @@ var __webpack_require__ = {};
6156
});
6257
};
6358
})();
64-
/************************************************************************/ var __webpack_exports__ = {};
65-
// ESM COMPAT FLAG
59+
var __webpack_exports__ = {};
6660
__webpack_require__.r(__webpack_exports__);
67-
// EXPORTS
6861
__webpack_require__.d(__webpack_exports__, {
69-
default: ()=>/* binding */ src_rslib_entry_
62+
default: ()=>src_rslib_entry_
7063
});
7164
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
7265
require("react");
@@ -91,8 +84,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
9184
]
9285
})
9386
});
94-
/* ESM default export */ const logoreact = SvgLogo;
95-
/* ESM default export */ const src_rslib_entry_ = logoreact;
87+
const logoreact = SvgLogo;
88+
const src_rslib_entry_ = logoreact;
9689
var __webpack_export_target__ = exports;
9790
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
9891
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {

tests/integration/extension-alias/__snapshots__/index.test.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ exports[`resolve.extensionAlias should work 1`] = `
55
var __webpack_exports__ = {};
66
const bar = 'bar';
77
const foo = 'foo';
8-
// Relative import paths need explicit file extensions in ECMAScript imports
9-
// when '--moduleResolution' is 'node16' or 'nodenext'.
108
console.log(foo + bar);
119
var __webpack_export_target__ = exports;
1210
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
@@ -19,8 +17,6 @@ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_targe
1917
exports[`resolve.extensionAlias should work 2`] = `
2018
"const bar = 'bar';
2119
const foo = 'foo';
22-
// Relative import paths need explicit file extensions in ECMAScript imports
23-
// when '--moduleResolution' is 'node16' or 'nodenext'.
2420
console.log(foo + bar);
2521
"
2622
`;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
/*! Legal Comment */
2+
import { jsx } from 'react/jsx-runtime';
3+
14
export const foo = () => {};
25

36
const bar = () => {};
47
const baz = () => {
58
return bar();
69
};
10+
11+
// normal comment
12+
export const Button = () => /*#__PURE__*/ jsx('button', {});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "minify-diabled-config-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}

tests/integration/minify/config/rslib.config.ts renamed to tests/integration/minify/config/disabled/rslib.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export default defineConfig({
66
lib: [generateBundleEsmConfig()],
77
output: {
88
minify: false,
9+
externals: ['react/jsx-runtime'],
910
},
1011
source: {
1112
entry: {
12-
index: path.resolve(__dirname, '../__fixtures__/src/index.ts'),
13+
index: path.resolve(__dirname, '../../__fixtures__/src/index.ts'),
1314
},
1415
},
1516
});

0 commit comments

Comments
 (0)