Skip to content

Commit

Permalink
feat: support read environments source.entry config (#2643)
Browse files Browse the repository at this point in the history
Co-authored-by: neverland <[email protected]>
  • Loading branch information
9aoy and chenjiahan authored Jun 20, 2024
1 parent 552facf commit e7163d7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/src/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function createPublicContext(
'configPath',
'tsconfigPath',
'bundlerType',
'environments',
];

// Using Proxy to get the current value of context.
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ export const pluginEntry = (): RsbuildPlugin => ({

setup(api) {
api.modifyBundlerChain(
async (chain, { target, isServer, isServiceWorker }) => {
const config = api.getNormalizedConfig();
async (chain, { environment, isServer, isServiceWorker }) => {
const config = api.getNormalizedConfig({ environment });
const { preEntry } = config.source;
const entry =
target === 'web' ? api.context.entry : getEntryObject(config, target);
const { entry } = api.context.environments[environment];

const injectCoreJsEntry =
config.output.polyfill === 'entry' && !isServer && !isServiceWorker;
Expand Down
20 changes: 20 additions & 0 deletions packages/core/tests/__snapshots__/entry.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`plugin-entry > should apply environments entry config correctly 1`] = `
[
{
"entry": {
"index": [
"src/index.client",
],
},
},
{
"entry": {
"index": [
"src/index.ssr",
],
},
},
]
`;
27 changes: 27 additions & 0 deletions packages/core/tests/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,31 @@ describe('plugin-entry', () => {

expect(config).toEqual(item.expected);
});

it('should apply environments entry config correctly', async () => {
const rsbuild = await createStubRsbuild({
plugins: [pluginEntry()],
rsbuildConfig: {
environments: {
web: {
source: {
entry: {
index: './src/index.client',
},
},
},
ssr: {
source: {
entry: {
index: './src/index.ssr',
},
},
},
},
},
});

const configs = await rsbuild.initConfigs();
expect(configs).toMatchSnapshot();
});
});

0 comments on commit e7163d7

Please sign in to comment.