nmussy
Repos
40
Followers
15

Events

opened issue
Deploy-time value support

Is your feature request related to a problem? Please describe. When given an unresolvable token as a define: value, the build will naively add ${Token[TOKEN.123]} token strings instead of warning the user.

Describe the solution you'd like Ideally, unresolved token values should be detected, and the build delayed until they are somehow resolved. I don't see a simple or realistic way to do this, the user could be alerted when an unresolved/unsolvable token is detected.

Describe alternatives you've considered I'm using the aws-cdk-lib.aws_s3_deployment Source.data/jsonData() constructs, which do support deploy-time resolution, and fetch the generated JSON file on the fly at the start of my application.

As indicated in the docs, these data/jsonData files are generated and deployed by a custom resource, after the initial deployment.

Stack:

new BucketDeployment(this, 'deployment', {
  sources: [
    new TypeScriptSource('./src/index.tsx', {
      copyDir: './static',
      buildOptions: {
        platform: 'browser',
        define: {
          ['process.env.NODE_ENV']: '"development"',
          ['process.env.REACT_APP_AWS_REGION']: `"${Stack.of(this).region}"`,
        },
      },
    }),
    Source.jsonData('deploy-time-env.json', {
      REACT_APP_USER_POOL_ID: userPool.userPoolId,
      REACT_APP_USER_POOL_CLIENT_ID: userPoolClient.userPoolClientId,
    }),
  ],
  destinationBucket,
});

Additional context I don't think it is possible to give properly resolved define: values without outsourcing the esbuild process to Lambda/CodeBuild, after the initial deployment is completed. I doubt there is something cleaner than the alternative listed above, but please correct me if anyone can think of something better.

I'm just opening this issue to share my findings, and maybe increase user experience with some sort of hint/warning from the construct.

Created at 1 month ago
Created at 1 month ago