Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support read environments source.entry config #2643

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
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].entry;
chenjiahan marked this conversation as resolved.
Show resolved Hide resolved

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();
});
});
Loading