Skip to content

Variables in index.html is not injected properly (or injected after HtmlWebpackPlugin optimizations) #6689

Closed
@olessavluk

Description

@olessavluk

Is this a bug report?

Yes

Did you try recovering your dependencies?

1.13.0

Which terms did you search for in User Guide?

Referencing Environment Variables in the HTML

Environment

Environment Info:

  System:
    OS: macOS 10.14.3
    CPU: x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.13.0 - ~/.nvm/versions/node/v10.15.3/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 72.0.3626.121
    Firefox: 64.0
    Safari: 12.0.3
  npmPackages:
    react: Not Found
    react-dom: Not Found
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: 2.1.8

Steps to Reproduce

  1. Add the following to index.html file:
<meta name="NODE_ENV" content="%NODE_ENV%" />
<% if ("%NODE_ENV%" === "production") { %>
<script>
  console.log('it works!');
</script>
<% } %>
  1. yarn build

Expected Behavior

%NODE_ENV% will be injected properly:

<meta name="NODE_ENV" content="production" />
<script>
  console.log('it works!');
</script>

Actual Behavior

Script tag is missing:

<meta name="NODE_ENV" content="production" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions