Skip to content

Plugin env #77

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

Closed
wants to merge 3 commits into from
Closed

Conversation

alfredosalzillo
Copy link
Contributor

Added an env plugin to replace {{ENV_VAR_NAME}} with the value at compile time.

Why

It's useful to use env variables in SSG mode or SSR without using the useDeno hook.

Example usage

// file aleph.config.js
import env from 'https://deno.land/x/aleph/plugins/env.ts'
export default {
  plugins: [
   env(),
  ],
};

into code

const API_URL = '{{APP_BASE_API_URL}}';

will replace {{APP_BASE_API_URL}} with the result of Deno.env.get('APP_BASE_API_URL').

@alfredosalzillo alfredosalzillo requested a review from ije as a code owner January 3, 2021 01:09
Copy link
Member

@shadowtime2000 shadowtime2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the idea of replacing {{env variable}}. Might better to use some AST transformations instead.

@alfredosalzillo
Copy link
Contributor Author

The problem with an AST transformation is that as of today there isn't any AST library for deno. We should use the node typescript.compileSource.

Adding the AST API to the deno namespace was discussed but for now, is on standby denoland/deno#6893 (comment).

@shadowtime2000
Copy link
Member

@alfredosalzillo The Deno team has decided not to have an AST API in the Deno namespace but there are other solutions, like deno_swc which seems like a good one.

@shadowtime2000
Copy link
Member

I am going to close this PR, I am going to open another issue to discuss this before we implement it.

@shadowtime2000 shadowtime2000 mentioned this pull request Jan 3, 2021
@shadowtime2000 shadowtime2000 linked an issue Jan 3, 2021 that may be closed by this pull request
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.

SWC Macro
2 participants