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

Remove unused config for ejs #140

Merged
merged 1 commit into from
May 22, 2022

Conversation

nvh95
Copy link
Member

@nvh95 nvh95 commented May 22, 2022

Goal

  • Remove redundant ejs config in vite.config.ts.
  • I thought that config inject.data.env is to enject to process.env, but it's not correct. accessing <% if (process.env.VERCEL_ENV === 'production') { %> is supported by ejs natively.
  • If I config as
inject: {
  data: {
    env,
  },
},

I should write in the index.html like this

<% if (env.VERCEL_ENV === 'production') { %>

But I use process.env.VERCEL_ENV, so no need any injection.

How to test

Change

  • Build the app in PROD mode
VERCEL_ENV=production npm run build

=> We should see the cloudflare analytics in the index.html

  • Build the app in Preview mode
VERCEL_ENV=preview npm run build

=> We should not see the cloudflare analytics in the index.html

cc: @michaelrambeau

@vercel
Copy link

vercel bot commented May 22, 2022

@nvh95 is attempting to deploy a commit to the Best of JavaScript Team on Vercel.

A member of the Team first needs to authorize it.

@michaelrambeau michaelrambeau self-requested a review May 22, 2022 22:20
Copy link
Member

@michaelrambeau michaelrambeau left a comment

Choose a reason for hiding this comment

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

Thank you very much @nvh95

The simpler, the better 😄

According to some tests I did yesterday, it works, we are able to use directly variables provided by Vercel platform (E.g. VERCEL_ENV that is equal to production or preview, depending on the branch)

Just for the records, the test I did I:

  • I added the following code to the HTML template
  • I pushed a branch, deployed on Vercel
 <% if (process.env.VERCEL_ENV === 'preview') { %>
    <script>
      console.log("preview");
    </script>
 <% } %>

@michaelrambeau michaelrambeau merged commit 346a124 into bestofjs:develop May 22, 2022
@nvh95 nvh95 deleted the remove-redundant-config branch May 23, 2022 01:19
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.

None yet

2 participants