preboot / angular-webpack

A complete, yet simple, starter for Angular v2+ using webpack
MIT License
1.29k stars 556 forks source link

How to use webpack properties in src/index.html ? #272

Closed samfrach closed 7 years ago

samfrach commented 7 years ago

Hello,

I would like to set properties in my html file.

In webpack.config.js, I have added an entry in the "DefinePlugin .. 'process.env' line.

In my index.html file, I've add a <%= process.env.myVariable %> line... but it fails...

Reference Error on the value of myVariable.... Is there a syntax to say "just display it" or is it looking for a file with the given name ?

thank you for your help and congrats for this projet, that helps me a lot :)

samfrach commented 7 years ago

I could do it .. .but it is ugly....

var mydata = { v1: "\"Hello\"" }; new webpack.DefinePlugin({ // Environment helpers 'process.env': { ENV: JSON.stringify(ENV), myData: myData } }),

.... if I don't set the \" (backslash+quote) ... then my value is copied without quotes as a variable...

do you know why ?

thank

Foxandxss commented 7 years ago

I don't, that is something that never occurred to me to do. Sounds ugly :/