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

refactor!: update api.context, remove entry, targets properties #2680

Merged
merged 9 commits into from
Jun 24, 2024

Conversation

9aoy
Copy link
Contributor

@9aoy 9aoy commented Jun 24, 2024

Summary

Remove api.context.entry and api.context.targets, use api.environment instead.

The distPath and tsconfigPath may be different in different environments. Rsbuild will try to get the parent distPath of environments as context.distPath, it is recommended to use api.environment[name] instead of api.context.

const pluginFoo = () => ({
  setup(api) {
      api.modifyBundlerChain((chain, { environment }) => {
-            const { entry,  targets, tsconfigPath, distPath } = api.context;
+            const { entry,  target, tsconfigPath, distPath } = api.environments[environment];
    });
  },
});

Related Links

#2620

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jun 24, 2024

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit dfe9805
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/667937a3e41cee00080d9cdb
😎 Deploy Preview https://deploy-preview-2680--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 77 (🔴 down 4 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@chenjiahan chenjiahan changed the title refactor: update api.context refactor!: update api.context, remove entry, targets properties Jun 24, 2024
@chenjiahan chenjiahan merged commit d72dd09 into web-infra-dev:main Jun 24, 2024
11 checks passed
@colinaaa
Copy link
Contributor

colinaaa commented Jul 3, 2024

I cannot find api.environments(or api.context.environments) in Rsbuild 1.0.0-alpha.

Seems like it has been changed to utils.environments in #2721.

But the environements does not exist in the utils of api.onDevCompileDone.

So, how could I migrate the following code:

api.onDevCompileDone(async ({ isFirstCompile, stats }) => {
  const entries = Object.keys(api.context.entry)
})

@chenjiahan
Copy link
Member

Yeah we have changed the design and no longer provides "api.context.environments".

The onDevCompileDone callback should have a environements param, @9aoy do we missing it

@9aoy
Copy link
Contributor Author

9aoy commented Jul 3, 2024

So, how could I migrate the following code:

api.onDevCompileDone(async ({ isFirstCompile, stats }) => {
  const entries = Object.keys(api.context.entry)
})

@colinaaa The environment api is not fully complete yet (also doc and features). And it seems that the environments parameter is missing in onDevCompileDone hook.
When completed, it should be migrated as follows:

api.onDevCompileDone(async ({ isFirstCompile, stats, environments }) => {
  const entries = Object.values(environments).map(e => e.entry)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants