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.

Suleman
  • 644
  • 3
  • 12
  • 23
  • Possible duplicate of [Multiple html files using webpack](https://stackoverflow.com/questions/39798095/multiple-html-files-using-webpack). I don't know for sure if this will solve your question but I hope it helps – Phil Oct 09 '19 at 05: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. – Suleman Oct 09 '19 at 09:46
  • Like I said, I just hoped it might help – Phil Oct 09 '19 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. – madflow Oct 10 '19 at 08:45
  • @Suleman did you found solution? – zdm Jan 18 '20 at 11:23

0 Answers0