Skip to content

Conversation

jkrems
Copy link
Contributor

@jkrems jkrems commented Sep 30, 2024

Ensures that conditional exports/imports work as intended in ng serve and ng build:

  1. For optimized builds, the "production" condition is enabled.
  2. For non-optimized builds, the "development" condition is enabled.

This allows quick conditional logic like the following to work as expected:

import {verboseLogging} from '#logger';

The file can be switched in the imports field in package.json:

// ...
  "imports": {
    "#logger": {
      "development": "./src/logging/debug.ts",
      "default": "./src/logging/noop.ts"
    }
  },

Something similar already (and continues to) work for SSR vs browser code.
The difference can be expressed using the "browser" condition:

// ...
  "imports": {
    "#crashReporter": {
      "browser": "./src/crash/sendBeacon.ts",
      "default": "./src/crash/writeCrashDumpFile.ts"
    }
  },

References:

@jkrems
Copy link
Contributor Author

jkrems commented Sep 30, 2024

The changes themselves should be in fairly good shape but leaving as draft until the next tooling meeting.

@brandonroberts
Copy link
Contributor

Will there be a condition for the SSR vs client build also?

@jkrems
Copy link
Contributor Author

jkrems commented Oct 3, 2024

Will there be a condition for the SSR vs client build also?

I think that should already exist. I've used the "browser" condition successfully which comes with esbuild/Vite natively.

@jkrems jkrems force-pushed the jk-dev-condition branch 2 times, most recently from 67bdb23 to 646bd39 Compare October 9, 2024 18:22
Ensures that we consistently set "development" for non-optimized and
"production" for optimized builds. This is consistent with other
bundlers (Vite/webpack/parcel/...).
@jkrems
Copy link
Contributor Author

jkrems commented Oct 9, 2024

I removed the code for import.meta.env.DEV since that API still needs more discussion. But I did add a test to verify that the "browser" condition works as expected.

@jkrems jkrems marked this pull request as ready for review October 9, 2024 18:25
@jkrems jkrems requested a review from clydin October 9, 2024 18:25
@jkrems jkrems added action: merge The PR is ready for merge by the caretaker target: feature This PR is targeted for a feature branch (outside of main and semver branches) target: minor This PR is targeted for the next minor release and removed target: feature This PR is targeted for a feature branch (outside of main and semver branches) labels Oct 9, 2024
@jkrems jkrems merged commit c48d694 into angular:main Oct 9, 2024
34 checks passed
@jkrems jkrems deleted the jk-dev-condition branch October 9, 2024 18:48
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants