1

Is it possible to use env variables inside a .html file (public path) but not the index.html one i have tried and it works fine in index.html but in any other .html file it doesn't work, for example if write this in img src:

<img src="<%= VUE_APP_API_Base %>/Image" border="0" style="width: 468px; height:60px;">

It doesn't parse anything from the .env files and src is written as it is instead of using the value of env variable. When visiting that html page url encode error is thrown in console.

Structure of my directory is:

public
|-- index.html
`-- sub-folder
    `-- sub.html <<<=== This is the file where I want to use .env variable

EDIT: To clarify about duplicate, I am asking specifically how to include a variable from .env file in a non-root html file (index.html), the duplicate asks about using multiple html files with webpack which is a different scenario

Link to Vue.js docs explaining the solution for this problem

The global BASE_URL and NODE_ENV actually works fine but not anything from my .env files.

5
  • Possible duplicate of Multiple html files using webpack. I don't know for sure if this will solve your question but I hope it helps Commented Oct 9, 2019 at 5:05
  • 1
    @Phil I don't see how is this a duplicate, that question asked about using multi-html files using webpack, I'm not asking for using multiple files or root paths, I am just asking how to include .env variable in a non-root html file. Commented Oct 9, 2019 at 9:46
  • Like I said, I just hoped it might help Commented Oct 9, 2019 at 10:33
  • What do you mean by "visiting" that other html file? Is this also processed by Webpack? Maybe it is best when you post the contents of these files. Commented Oct 10, 2019 at 8:45
  • @Suleman did you found solution? Commented Jan 18, 2020 at 11:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.