gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

Load title in index.html from env file #26

Open gloriaJun opened 5 years ago

gloriaJun commented 5 years ago

Version

"html-webpack-plugin": "^3.2.0",

env file

TITLE=Conduit
API_URL=https://conduit.productionready.io/api

webpack config file

  plugins: [
    new HtmlWebpackPlugin({
      template: `${TEMPLATE_DIRNAME}/${TEMPLATE_ENTRY_FILENAME}`,
      favicon: `${TEMPLATE_DIRNAME}/favicon.ico`,
      filename: TEMPLATE_ENTRY_FILENAME,
      title: process.env.TITLE,
    }),
  ],

public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

Reference