Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ async function composeLibRsbuildConfig(
const assetConfig = composeAssetConfig(bundle, format);

const entryChunkConfig = composeEntryChunkConfig({
useLoader: advancedEsm !== true,
useLoader: advancedEsm !== true && (format === 'esm' || format === 'iife'),
enabledImportMetaUrlShim: enabledShims.cjs['import.meta.url'],
contextToWatch: outBase,
});
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/plugins/EntryChunkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ class EntryChunkPlugin {
compilation.updateAsset(name, (old) => {
const oldSource = old.source().toString();
const replaceSource = new rspack.sources.ReplaceSource(old);
if (
oldSource.startsWith('use strict;') ||
oldSource.startsWith('"use strict";')

if (oldSource.startsWith('#!')) {
const firstLineEnd = oldSource.indexOf('\n');
replaceSource.insert(firstLineEnd + 1, IMPORT_META_URL_SHIM);
} else if (
oldSource.startsWith("'use strict'") ||
oldSource.startsWith('"use strict"')
) {
replaceSource.replace(
0,
11, // 'use strict;'.length,
11,
`"use strict";\n${IMPORT_META_URL_SHIM}`,
);
} else {
Expand Down
45 changes: 0 additions & 45 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2425,17 +2425,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
}
}
]
},
/* config.module.rule('Rslib:js-entry-loader') */
{
test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
issuer: /^$/,
use: [
/* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */
{
loader: '<WORKSPACE>/dist/entryModuleLoader.js'
}
]
}
]
},
Expand Down Expand Up @@ -3072,17 +3061,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
}
}
]
},
/* config.module.rule('Rslib:js-entry-loader') */
{
test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
issuer: /^$/,
use: [
/* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */
{
loader: '<WORKSPACE>/dist/entryModuleLoader.js'
}
]
}
]
},
Expand Down Expand Up @@ -4312,17 +4290,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
generator: {
filename: 'static/wasm/[contenthash:8].module.wasm'
}
},
/* config.module.rule('Rslib:js-entry-loader') */
{
test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
issuer: /^$/,
use: [
/* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */
{
loader: '<WORKSPACE>/dist/entryModuleLoader.js'
}
]
}
]
},
Expand Down Expand Up @@ -4834,10 +4801,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
],
"setup": [Function],
},
{
"name": "rsbuild:lib-entry-chunk",
"setup": [Function],
},
],
"resolve": {
"alias": {
Expand Down Expand Up @@ -5096,10 +5059,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"name": "rsbuild:fix-js-module-type",
"setup": [Function],
},
{
"name": "rsbuild:lib-entry-chunk",
"setup": [Function],
},
],
"resolve": {
"alias": {
Expand Down Expand Up @@ -5541,10 +5500,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"name": "rsbuild:fix-js-module-type",
"setup": [Function],
},
{
"name": "rsbuild:lib-entry-chunk",
"setup": [Function],
},
{
"name": "rsbuild:module-federation-enhanced",
"setup": [Function],
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/directive/shebang/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from '@rslib/core';
import { generateBundleEsmConfig } from 'test-helper';
import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';

const esmShared = {
source: {
Expand All @@ -20,6 +20,11 @@ const esmSharedBundleFalse = {

export default defineConfig({
lib: [
generateBundleCjsConfig({
output: {
distPath: './dist/bundle/cjs0',
},
}),
generateBundleEsmConfig({
...esmShared,
shims: { esm: { __dirname: true, __filename: true } },
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/minify/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ describe('minify config (mf)', () => {
const { mfExposeEntry } = await buildAndGetResults({ fixturePath });
// biome-ignore format: snapshot
expect(mfExposeEntry).toMatchInlineSnapshot(`
"/*! For license information please see __federation_expose_default_export.fd95b46e.js.LICENSE.txt */
"use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["525"],{807:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{Button:()=>Button,foo:()=>foo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(491);/*! Legal Comment */const foo=()=>{};const Button=()=>/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{})}}]);"
"/*! For license information please see __federation_expose_default_export.8ba7966f.js.LICENSE.txt */
"use strict";(globalThis["default_minify"]=globalThis["default_minify"]||[]).push([["525"],{510:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{Button:()=>Button,foo:()=>foo});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(491);/*! Legal Comment */const foo=()=>{};const Button=()=>/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{})}}]);"
`);
});

Expand All @@ -86,7 +86,7 @@ describe('minify config (mf)', () => {
expect(mfExposeEntry).toMatchInlineSnapshot(`
""use strict";
(globalThis["disable_minify"] = globalThis["disable_minify"] || []).push([["525"], {
807: (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
510: (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Button: () => (Button),
Expand Down
Loading