Skip to content

Commit caba130

Browse files
committed
refactor: supersede entry query by entry dedicated loader
1 parent 49728b4 commit caba130

File tree

17 files changed

+134
-128
lines changed

17 files changed

+134
-128
lines changed

packages/core/src/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ const traverseEntryQuery = (
941941
};
942942

943943
export const appendEntryQuery = (entries: RsbuildConfigEntry): RsbuildEntry =>
944-
traverseEntryQuery(entries, (item) => `${item}?${RSLIB_ENTRY_QUERY}`);
944+
traverseEntryQuery(entries, (item) => `${item}`);
945945

946946
export const resolveEntryPath = (
947947
entries: RsbuildConfigEntry,
@@ -1020,7 +1020,8 @@ const composeEntryConfig = async (
10201020
return {
10211021
entryConfig: {
10221022
source: {
1023-
entry: appendEntryQuery(resolveEntryPath(entries, root)),
1023+
// entry: appendEntryQuery(resolveEntryPath(entries, root)),
1024+
entry: resolveEntryPath(entries, root),
10241025
},
10251026
},
10261027
outBase: null,
@@ -1126,7 +1127,8 @@ const composeEntryConfig = async (
11261127
rspack: {
11271128
entry: async () => {
11281129
const { resolvedEntries } = await scanGlobEntries(false);
1129-
return appendEntryQuery(resolvedEntries);
1130+
// return appendEntryQuery(resolvedEntries);
1131+
return resolvedEntries;
11301132
},
11311133
},
11321134
},

packages/core/src/plugins/EntryChunkPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ const entryModuleLoaderRsbuildPlugin = (): RsbuildPlugin => ({
205205
setup(api) {
206206
api.modifyBundlerChain((config, { CHAIN_ID }) => {
207207
config.module
208-
.rule(CHAIN_ID.RULE.JS)
208+
.rule(`${CHAIN_ID.RULE.JS}:rslib_entry_loader`)
209+
.test(/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/)
210+
.issuer(/^$/)
209211
.use(LOADER_NAME)
210212
.loader(require.resolve('./entryModuleLoader.js'));
211213
});

packages/core/src/plugins/entryModuleLoader.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ function splitFromFirstLine(text: string): [string, string] {
1717
const loader: Rspack.LoaderDefinition = function loader(source) {
1818
let result = source;
1919

20-
if (this.resourceQuery === `?${RSLIB_ENTRY_QUERY}`) {
21-
const [firstLine1, rest] = splitFromFirstLine(result);
20+
// if (this.resourceQuery === `?${RSLIB_ENTRY_QUERY}`) {
21+
const [firstLine1, rest] = splitFromFirstLine(result);
2222

23-
if (SHEBANG_REGEX.test(firstLine1)) {
24-
result = rest;
25-
}
23+
if (SHEBANG_REGEX.test(firstLine1)) {
24+
result = rest;
25+
}
2626

27-
const [firstLine2, rest2] = splitFromFirstLine(result);
28-
if (REACT_DIRECTIVE_REGEX.test(firstLine2)) {
29-
result = rest2;
30-
}
27+
const [firstLine2, rest2] = splitFromFirstLine(result);
28+
if (REACT_DIRECTIVE_REGEX.test(firstLine2)) {
29+
result = rest2;
3130
}
31+
// }
3232

3333
return result;
3434
};

packages/core/tests/entry.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe('appendEntryQuery', () => {
1010
}),
1111
).toMatchInlineSnapshot(`
1212
{
13-
"foo": "src/foo.js?__rslib_entry__",
14-
"index": "src/index.js?__rslib_entry__",
13+
"foo": "src/foo.js",
14+
"index": "src/index.js",
1515
}
1616
`);
1717
});
@@ -25,11 +25,11 @@ describe('appendEntryQuery', () => {
2525
).toMatchInlineSnapshot(`
2626
{
2727
"foo": [
28-
"src/foo.js?__rslib_entry__",
28+
"src/foo.js",
2929
],
3030
"index": [
31-
"src/index.ts?__rslib_entry__",
32-
"src/extra.ts?__rslib_entry__",
31+
"src/index.ts",
32+
"src/extra.ts",
3333
],
3434
}
3535
`);
@@ -54,13 +54,13 @@ describe('appendEntryQuery', () => {
5454
"src/dep.js",
5555
],
5656
"import": [
57-
"src/foo.js?__rslib_entry__",
57+
"src/foo.js",
5858
],
5959
},
6060
"index": {
6161
"import": [
62-
"src/index.ts?__rslib_entry__",
63-
"src/extra.ts?__rslib_entry__",
62+
"src/index.ts",
63+
"src/extra.ts",
6464
],
6565
"layer": "l1",
6666
},
@@ -84,23 +84,23 @@ describe('appendEntryQuery', () => {
8484
}),
8585
).toMatchInlineSnapshot(`
8686
{
87-
"bar": "src/bar.ts?__rslib_entry__",
87+
"bar": "src/bar.ts",
8888
"baz": [
89-
"src/baz.ts?__rslib_entry__",
90-
"src/bar.ts?__rslib_entry__",
89+
"src/baz.ts",
90+
"src/bar.ts",
9191
],
9292
"foo": {
9393
"dependOn": [
9494
"src/dep.js",
9595
],
9696
"import": [
97-
"src/foo.js?__rslib_entry__",
97+
"src/foo.js",
9898
],
9999
},
100100
"index": {
101101
"import": [
102-
"src/index.ts?__rslib_entry__",
103-
"src/extra.ts?__rslib_entry__",
102+
"src/index.ts",
103+
"src/extra.ts",
104104
],
105105
"layer": "l1",
106106
},

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ console.log(draft_namespaceObject);
77
`;
88

99
exports[`use asset/source 2`] = `
10-
"const draft_rslib_entry_namespaceObject = "this is a txt file\\nthis is a txt file\\n";
11-
export { draft_rslib_entry_namespaceObject as default };
10+
"const draft_namespaceObject = "this is a txt file\\nthis is a txt file\\n";
11+
export { draft_namespaceObject as default };
1212
"
1313
`;
1414

@@ -19,8 +19,8 @@ console.log(draft_namespaceObject);
1919
`;
2020

2121
exports[`use source.assetInclude 2`] = `
22-
"import draft_rslib_entry_namespaceObject from "../static/assets/draft.txt";
23-
export { draft_rslib_entry_namespaceObject as default };
22+
"import draft_namespaceObject from "../static/assets/draft.txt";
23+
export { draft_namespaceObject as default };
2424
"
2525
`;
2626

@@ -49,8 +49,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
4949
]
5050
})
5151
});
52-
const logo_rslib_entry_ = __rslib_svgr_url__0__;
53-
export { SvgLogo as ReactComponent, logo_rslib_entry_ as default };
52+
const logo = __rslib_svgr_url__0__;
53+
export { SvgLogo as ReactComponent, logo as default };
5454
"
5555
`;
5656

@@ -81,7 +81,7 @@ var __webpack_require__ = {};
8181
var __webpack_exports__ = {};
8282
__webpack_require__.r(__webpack_exports__);
8383
__webpack_require__.d(__webpack_exports__, {
84-
default: ()=>logo_rslib_entry_,
84+
default: ()=>logo,
8585
ReactComponent: ()=>SvgLogo
8686
});
8787
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
@@ -107,7 +107,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
107107
]
108108
})
109109
});
110-
const logo_rslib_entry_ = require("../static/svg/logo.svg");
110+
const logo = require("../static/svg/logo.svg");
111111
exports.ReactComponent = __webpack_exports__.ReactComponent;
112112
exports["default"] = __webpack_exports__["default"];
113113
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -144,8 +144,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
144144
]
145145
})
146146
});
147-
const logo_rslib_entry_ = SvgLogo;
148-
export { logo_rslib_entry_ as default };
147+
const logo = SvgLogo;
148+
export { logo as default };
149149
"
150150
`;
151151

@@ -176,7 +176,7 @@ var __webpack_require__ = {};
176176
var __webpack_exports__ = {};
177177
__webpack_require__.r(__webpack_exports__);
178178
__webpack_require__.d(__webpack_exports__, {
179-
default: ()=>logo_rslib_entry_
179+
default: ()=>logo
180180
});
181181
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
182182
require("react");
@@ -201,7 +201,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
201201
]
202202
})
203203
});
204-
const logo_rslib_entry_ = SvgLogo;
204+
const logo = SvgLogo;
205205
exports["default"] = __webpack_exports__["default"];
206206
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
207207
"default"
@@ -213,15 +213,15 @@ Object.defineProperty(exports, '__esModule', {
213213
`;
214214

215215
exports[`use svgr > should only contain url default export 1`] = `
216-
"import logo2_rslib_entry_namespaceObject from "../static/svg/logo2.svg";
217-
export { logo2_rslib_entry_namespaceObject as default };
216+
"import logo2_namespaceObject from "../static/svg/logo2.svg";
217+
export { logo2_namespaceObject as default };
218218
"
219219
`;
220220

221221
exports[`use svgr > should only contain url default export 2`] = `
222222
""use strict";
223223
var __webpack_modules__ = {
224-
"./src/assets/logo2.svg?__rslib_entry__": function(module) {
224+
"./src/assets/logo2.svg": function(module) {
225225
module.exports = require("../static/svg/logo2.svg");
226226
}
227227
};
@@ -235,7 +235,7 @@ function __webpack_require__(moduleId) {
235235
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
236236
return module.exports;
237237
}
238-
var __webpack_exports__ = __webpack_require__("./src/assets/logo2.svg?__rslib_entry__");
238+
var __webpack_exports__ = __webpack_require__("./src/assets/logo2.svg");
239239
exports["default"] = __webpack_exports__["default"];
240240
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
241241
"default"

tests/integration/asset/index.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ test('set the size threshold to inline static assets', async () => {
3636
const { content: logoJs2 } = queryContent(contents.esm2!, /assets\/logo\.js/);
3737
expect(indexJs2).toMatchInlineSnapshot(`
3838
"import * as __WEBPACK_EXTERNAL_MODULE__assets_logo_js_450929b7__ from "./assets/logo.js";
39-
const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE__assets_logo_js_450929b7__["default"];
40-
export { src_rslib_entry_ as default };
39+
const src = __WEBPACK_EXTERNAL_MODULE__assets_logo_js_450929b7__["default"];
40+
export { src as default };
4141
"
4242
`);
4343
expect(logoJs2).toMatchInlineSnapshot(`
44-
"import logo_rslib_entry_namespaceObject from "../static/svg/logo.svg";
45-
export { logo_rslib_entry_namespaceObject as default };
44+
"import logo_namespaceObject from "../static/svg/logo.svg";
45+
export { logo_namespaceObject as default };
4646
"
4747
`);
4848
// cjs
@@ -57,7 +57,7 @@ test('set the size threshold to inline static assets', async () => {
5757
expect(logoCjs2).toMatchInlineSnapshot(`
5858
""use strict";
5959
var __webpack_modules__ = {
60-
"./src/assets/logo.svg?__rslib_entry__": function(module) {
60+
"./src/assets/logo.svg": function(module) {
6161
module.exports = require("../static/svg/logo.svg");
6262
}
6363
};
@@ -71,7 +71,7 @@ test('set the size threshold to inline static assets', async () => {
7171
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
7272
return module.exports;
7373
}
74-
var __webpack_exports__ = __webpack_require__("./src/assets/logo.svg?__rslib_entry__");
74+
var __webpack_exports__ = __webpack_require__("./src/assets/logo.svg");
7575
exports["default"] = __webpack_exports__["default"];
7676
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
7777
"default"
@@ -105,8 +105,8 @@ test('set the assets filename with hash', async () => {
105105
/assets\/image\.js/,
106106
);
107107
expect(imageJs1).toMatchInlineSnapshot(`
108-
"import image_rslib_entry_namespaceObject from "../static/image/image.c74653c1.png";
109-
export { image_rslib_entry_namespaceObject as default };
108+
"import image_namespaceObject from "../static/image/image.c74653c1.png";
109+
export { image_namespaceObject as default };
110110
"
111111
`);
112112
// cjs
@@ -117,7 +117,7 @@ test('set the assets filename with hash', async () => {
117117
expect(imageCjs1).toMatchInlineSnapshot(`
118118
""use strict";
119119
var __webpack_modules__ = {
120-
"./src/assets/image.png?__rslib_entry__": function(module) {
120+
"./src/assets/image.png": function(module) {
121121
module.exports = require("../static/image/image.c74653c1.png");
122122
}
123123
};
@@ -131,7 +131,7 @@ test('set the assets filename with hash', async () => {
131131
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
132132
return module.exports;
133133
}
134-
var __webpack_exports__ = __webpack_require__("./src/assets/image.png?__rslib_entry__");
134+
var __webpack_exports__ = __webpack_require__("./src/assets/image.png");
135135
exports["default"] = __webpack_exports__["default"];
136136
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
137137
"default"
@@ -165,8 +165,8 @@ test('set the assets output path', async () => {
165165
/assets\/image\.js/,
166166
);
167167
expect(imageJs1).toMatchInlineSnapshot(`
168-
"import image_rslib_entry_namespaceObject from "../assets/bundleless/image.png";
169-
export { image_rslib_entry_namespaceObject as default };
168+
"import image_namespaceObject from "../assets/bundleless/image.png";
169+
export { image_namespaceObject as default };
170170
"
171171
`);
172172
// cjs
@@ -177,7 +177,7 @@ test('set the assets output path', async () => {
177177
expect(imageCjs1).toMatchInlineSnapshot(`
178178
""use strict";
179179
var __webpack_modules__ = {
180-
"./src/assets/image.png?__rslib_entry__": function(module) {
180+
"./src/assets/image.png": function(module) {
181181
module.exports = require("../assets/bundleless/image.png");
182182
}
183183
};
@@ -191,7 +191,7 @@ test('set the assets output path', async () => {
191191
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
192192
return module.exports;
193193
}
194-
var __webpack_exports__ = __webpack_require__("./src/assets/image.png?__rslib_entry__");
194+
var __webpack_exports__ = __webpack_require__("./src/assets/image.png");
195195
exports["default"] = __webpack_exports__["default"];
196196
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
197197
"default"
@@ -258,8 +258,8 @@ test('set the assets public path', async () => {
258258
(()=>{
259259
__webpack_require__.p = "/public/path/";
260260
})();
261-
const image_rslib_entry_namespaceObject = __webpack_require__.p + "static/image/image.png";
262-
export { image_rslib_entry_namespaceObject as default };
261+
const image_namespaceObject = __webpack_require__.p + "static/image/image.png";
262+
export { image_namespaceObject as default };
263263
"
264264
`);
265265
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
2525
]
2626
})
2727
});
28-
const logo_rslib_entry_ = __rslib_svgr_url__0__;
29-
export { SvgLogo as ReactComponent, logo_rslib_entry_ as default };
28+
const logo = __rslib_svgr_url__0__;
29+
export { SvgLogo as ReactComponent, logo as default };
3030
"
3131
`;
3232

@@ -57,7 +57,7 @@ var __webpack_require__ = {};
5757
var __webpack_exports__ = {};
5858
__webpack_require__.r(__webpack_exports__);
5959
__webpack_require__.d(__webpack_exports__, {
60-
default: ()=>logo_rslib_entry_,
60+
default: ()=>logo,
6161
ReactComponent: ()=>SvgLogo
6262
});
6363
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
@@ -83,7 +83,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
8383
]
8484
})
8585
});
86-
const logo_rslib_entry_ = require("../static/svg/logo.svg");
86+
const logo = require("../static/svg/logo.svg");
8787
exports.ReactComponent = __webpack_exports__.ReactComponent;
8888
exports["default"] = __webpack_exports__["default"];
8989
for(var __webpack_i__ in __webpack_exports__)if (-1 === [

0 commit comments

Comments
 (0)