Make all react app vars accessible in index.html (#1440)

* Make all vars accessiable in index.html

* Fix wrong env provieded to DefinePlugin

* Separate results from getClientEnvironment

* The `string` should be object instead of string

* Fix accessing wrong field

* Changed variables naming to `raw` and `stringified`

* Remove trailing commas
This commit is contained in:
Jih-Chi Lee
2017-02-10 11:41:03 +08:00
committed by Joe Haddad
parent b999405c67
commit 1d9159de23
3 changed files with 24 additions and 18 deletions

View File

@@ -198,12 +198,11 @@ module.exports = {
];
},
plugins: [
// Makes the public URL available as %PUBLIC_URL% in index.html, e.g.:
// Makes some environment variables available in index.html.
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
// In development, this will be an empty string.
new InterpolateHtmlPlugin({
PUBLIC_URL: publicUrl
}),
new InterpolateHtmlPlugin(env.raw),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
@@ -211,7 +210,7 @@ module.exports = {
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env),
new webpack.DefinePlugin(env.stringified),
// This is necessary to emit hot updates (currently CSS only):
new webpack.HotModuleReplacementPlugin(),
// Watcher doesn't work well if you mistype casing in a path so we use