Skip to content

Commit f96adda

Browse files
authored
fix: the moduleIds should be deterministic if the env is production and format is mf (#487)
1 parent da8191a commit f96adda

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

.changeset/smooth-parents-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rslib/core': patch
3+
---
4+
5+
fix: the moduleIds should be deterministic if the env is production and format is mf

packages/core/src/cli/mf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function changeEnvToDev(rsbuildConfig: RsbuildConfig) {
4141
rspack: {
4242
optimization: {
4343
nodeEnv: 'development',
44+
moduleIds: 'named',
4445
},
4546
},
4647
},

packages/core/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,9 @@ const composeFormatConfig = ({
594594
},
595595
// can not set nodeEnv to false, because mf format should build shared module.
596596
// If nodeEnv is false, the process.env.NODE_ENV in third-party packages's will not be replaced
597-
// now we have not provide dev mode for users, so we can always set nodeEnv as 'production'
598597
optimization: {
599598
nodeEnv: 'production',
599+
moduleIds: 'deterministic',
600600
},
601601
},
602602
},

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ vnode
141141
watchpack
142142
webm
143143
webp
144+
unstubAllEnvs

tests/integration/minify/index.test.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,28 @@ test('minify is enabled by default in mf format, bar and baz should be minified'
3333
const fixturePath = join(__dirname, 'mf/default');
3434
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
3535
// biome-ignore format: snapshot
36-
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["249"],{"../../__fixtures__/src/index.ts":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{foo:function(){return foo}});const foo=()=>{}}}]);"`);
36+
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["249"],{163:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{foo:function(){return foo}});const foo=()=>{}}}]);"`);
3737
});
3838

3939
test('minify is disabled by the user, bar and baz should not be minified', async () => {
4040
const fixturePath = join(__dirname, 'mf/config');
4141
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
42-
expect(mfExposeEntry).toMatchInlineSnapshot(`
43-
""use strict";
44-
(globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
45-
"../../__fixtures__/src/index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
46-
__webpack_require__.r(__webpack_exports__);
47-
__webpack_require__.d(__webpack_exports__, {
48-
foo: function() { return foo; }
49-
});
50-
const foo = ()=>{};
51-
const bar = ()=>{};
52-
const baz = ()=>{
53-
return bar();
54-
};
42+
43+
expect(mfExposeEntry).toMatchInlineSnapshot(`""use strict";
44+
(globalThis['disable_minify'] = globalThis['disable_minify'] || []).push([["249"], {
45+
"163": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
46+
__webpack_require__.r(__webpack_exports__);
47+
__webpack_require__.d(__webpack_exports__, {
48+
foo: function() { return foo; }
49+
});
50+
const foo = ()=>{};
51+
const bar = ()=>{};
52+
const baz = ()=>{
53+
return bar();
54+
};
5555
5656
57-
}),
57+
}),
5858
59-
}]);"
60-
`);
59+
}]);"`);
6160
});

0 commit comments

Comments
 (0)