<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexis Vigoureux on Medium]]></title>
        <description><![CDATA[Stories by Alexis Vigoureux on Medium]]></description>
        <link>https://medium.com/@alexisvigoureux?source=rss-1530f001f636------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*y09qwz1NjV3Rh1DtCqYn5A.jpeg</url>
            <title>Stories by Alexis Vigoureux on Medium</title>
            <link>https://medium.com/@alexisvigoureux?source=rss-1530f001f636------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 00:55:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexisvigoureux/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using env variables in Vendure React components]]></title>
            <link>https://alexisvigoureux.medium.com/using-env-variables-in-vendure-react-components-df68b5728a14?source=rss-1530f001f636------2</link>
            <guid isPermaLink="false">https://medium.com/p/df68b5728a14</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[vendure]]></category>
            <category><![CDATA[environment-variables]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alexis Vigoureux]]></dc:creator>
            <pubDate>Tue, 07 Nov 2023 18:30:49 GMT</pubDate>
            <atom:updated>2023-11-07T18:30:49.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWHx1Fgb-TYTrMX4wxTJqQ.png" /></figure><p>Historically, we’ve developed pages in React in our Vendure back office using the adminUI <a href="https://docs.vendure.io/reference/admin-ui-api/ui-devkit/admin-ui-extension#adminuiextensionlazymodule">extensions</a>. Our shop is developed in React, so we found it easier to use this library than Angular. But since <a href="https://www.vendure.io/blog/2023/10/announcing-vendure-v2-1">version 2.1</a> of Vendure, the adminUI is capable of embedding React custom components. This has a number of advantages, not least of which is that it saves CI time (and therefore cost if it is hosted by a cloud service), as we used to have to compile the React before supplying it to Angular.</p><p>Question comes: <strong>How do I access the environment variables?</strong> Now that Angular is managing the build of the application, the .tsx files are considered as standalone components. It is therefore no longer possible to access the environment variable via process.env.MY_VAR as in a React project created by <a href="https://create-react-app.dev/docs/adding-custom-environment-variables/">create-react-app</a>.</p><p>Issue: <strong>There is no way to add and access the environment variable built for adminUI components. </strong><a href="https://angular.io/guide/build">Angular serves environment variables</a>, but Vendure does not allow you to modify them.</p><p>Solutions: <strong>Create a static file with environment data and fetch the file on the client side.</strong></p><p>First, modify the <a href="https://docs.vendure.io/reference/core-plugins/admin-ui-plugin/">AdminUiPlugin</a> configuration to create the environment file:</p><pre>const { NODE_ENV } = process.env<br><br>AdminUiPlugin.init({<br>  ...<br>  app: {<br>    outputPath: path.join(__dirname, &#39;../admin-ui&#39;),<br>    extensions: [{<br>      staticAssets: [<br>        { ...getEnvConfigPath(), rename: &#39;environment.json&#39; },<br>      ],<br>    }],<br>    devMode: true<br>  }<br>})<br><br>function getEnvConfigPath(): { path: string } {<br>  switch (NODE_ENV) {<br>    case &#39;production&#39;:<br>      return {<br>        path: path.join(__dirname, &#39;/admin-static/env/env.production.json&#39;),<br>      }<br>    default:<br>      return {<br>        path: path.join(__dirname, &#39;/admin-static/env/env.json&#39;),<br>      }<br>  }<br>}</pre><p>Don’t forget to create the json files in src/admin-static/env (env.json and env.production.json)</p><p>If you generate the adminUI, you should see an environment.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*gq0yEVtPYoI0tGMcoWrCoQ.png" /></figure><p>Start your server, you should be able to access the contents of the file at the following address {baseUrl}/admin/assets/environment.json</p><p>Next, we create the service to retrieve the contents of the file for use in our components:</p><pre>import { useEffect, useState } from &#39;react&#39;<br><br>type AppConfig = {<br>  my_var: string<br>}<br><br>export const useAppConfig = (): { config?: AppConfig } =&gt; {<br>  const [config, setConfig] = useState&lt;AppConfig&gt;()<br><br>  useEffect(() =&gt; {<br>    const getConfig = async (): Promise&lt;AppConfig&gt; =&gt; {<br>      const response = await fetch(`${window.location.origin}/admin/assets/environment.json`, {<br>        headers: {<br>          &#39;Content-Type&#39;: &#39;application/json&#39;,<br>          Accept: &#39;application/json&#39;,<br>        },<br>      })<br><br>      return await response.json()<br>    }<br><br>    getConfig().then(setConfig)<br>  }, [])<br><br>  return { config }<br>}</pre><p>And we can use it in our components</p><pre>import { useAppConfig } from &#39;useAppConfig&#39;<br><br>export function MyComponent(): JSX.Element {<br>  const { config } = useAppConfig()<br><br>  return (<br>    &lt;div&gt;<br>        {config &amp;&amp; (<br>             &lt;div&gt;{config.my_var}&lt;/div&gt;<br>        )}<br>    &lt;/div&gt;<br>  ) <br>}</pre><p><strong>Bonus</strong>:</p><p>For Angular components, there is no way of adding environment variables either. The use of the previously created environment file can therefore be propagated. Here’s an example of how it can be used as an observable:</p><pre>import {defer, Observable, of} from &quot;rxjs&quot;<br>import {catchError, concatMap} from &quot;rxjs/operators&quot;<br><br>const appConfig$: Observable&lt;{my_var: string} | undefined&gt; = defer(() =&gt;<br>  fetch(`${window.location.origin}/admin/assets/environment.json`, {<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      Accept: &#39;application/json&#39;,<br>    },<br>  }),<br>).pipe(<br>  concatMap((response) =&gt; response.json()),<br>  catchError(() =&gt; {<br>    return of(undefined)<br>  }),<br>)<br><br>appConfig$.subscribe((data) =&gt; console.log(data))</pre><p>Thanks to Michael Bromley (CTO of Vendure) for the original idea.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df68b5728a14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Double shift key in Visual Studio Code]]></title>
            <link>https://alexisvigoureux.medium.com/double-shift-key-in-visual-studio-code-eaef156b493f?source=rss-1530f001f636------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaef156b493f</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[code-editor]]></category>
            <category><![CDATA[vscode]]></category>
            <dc:creator><![CDATA[Alexis Vigoureux]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 21:49:44 GMT</pubDate>
            <atom:updated>2021-04-20T21:49:44.582Z</atom:updated>
            <content:encoded><![CDATA[<p>For a long time, I worked with <a href="https://www.jetbrains.com/phpstorm/">PhpStorm </a>to write PHP and some Javascript. But my needs have evolved, and I’m going to move towards a stack using Typescript. So I decided to try <a href="https://code.visualstudio.com/">Visual Studio Code</a>.</p><p>Question comes: <strong>How can I avoid losing my keyboard shortcuts?</strong> The main obstacle to changing text editors is the modification of keyboard shortcuts, and therefore of automatisms/habits. So the <a href="https://marketplace.visualstudio.com/items?itemName=k--kato.intellij-idea-keybindings">IntelliJ IDEA Keybindings</a> extension fits this case almost perfectly.</p><p>Issue: <strong>The IntelliJ IDEA Keybindings extension does not support the quick open file </strong>(shift shift) available in PhpStorm. The equivalent in Vscode is ctrl+p but it’s overloaded by the IntelliJ IDEA Keybindings extension. We are therefore unable to use this native shortcut.</p><p>You will tell me that I can change the configuration of the keyboard shortcuts but I’m keen on the shift shift. This is a game changer, once you have used it, you can’t go back.</p><p><strong>Solutions</strong>: You need to put this to your keybindings.json:</p><pre>{<br>    &quot;key&quot;: &quot;shift shift&quot;,<br>    &quot;command&quot;: &quot;workbench.action.quickOpen&quot;<br>}</pre><p>This solution is valid from Vscode release 1.54.1 or higher.</p><p>Here is the link to the changelog of the feature: <a href="https://code.visualstudio.com/updates/v1_54#_modifier-only-keybindings">https://code.visualstudio.com/updates/v1_54#_modifier-only-keybindings</a></p><p><strong>Bonus</strong>:</p><p>Other keyboard shortcuts using a non-modifier key:</p><pre>{<br>    &quot;key&quot;: &quot;alt alt&quot;,<br>    &quot;command&quot;: &quot;workbench.action.showCommands&quot;<br>},<br>{<br>    &quot;key&quot;: &quot;ctrl ctrl&quot;,<br>    &quot;command&quot;: &quot;workbench.action.toggleSidebarVisibility&quot;<br>}</pre><p>Thanks to the Vscode community on Github for this feature.</p><p>Source: <a href="https://github.com/microsoft/vscode/issues/5280#issuecomment-792729308">https://github.com/microsoft/vscode/issues/5280#issuecomment-792729308</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaef156b493f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>