Update with-now-env to use env config (#6581)

* Update with-now-env to use `env` config
instead of webpack.DefinePlugin

* Remove mention of DefinePlugin from index page
This commit is contained in:
JJ Kasper 2019-03-08 13:41:07 -06:00 committed by Tim Neutkens
parent 3c04b0f4e1
commit 17da3f86ad
3 changed files with 4 additions and 13 deletions

View file

@ -1,4 +1,3 @@
const webpack = require('webpack')
/**
* After the next require you can use process.env to get your secrets
*/
@ -18,14 +17,7 @@ console.log({
* to share some variables with the client, configured at compile time.
*/
module.exports = {
webpack: config => {
config.plugins.push(
new webpack.DefinePlugin({
'process.env.SECRET': JSON.stringify(process.env.SECRET)
})
// Same as above
// new webpack.EnvironmentPlugin(['SECRET'])
)
return config
env: {
SECRET: process.env.SECRET
}
}

View file

@ -1,6 +1,6 @@
{
"name": "with-now-env",
"version": "1.0.0",
"version": "2.0.0",
"scripts": {
"dev": "next",
"build": "next build",

View file

@ -1,8 +1,7 @@
export default () => (
<div className='hello'>
<p>
Hello World! Here's a secret shared with the client using webpack
DefinePlugin: <strong>{process.env.SECRET}</strong>, the secret is shared
Hello World! Here's a secret shared with the client using Next env: <strong>{process.env.SECRET}</strong>, the secret is shared
at compile time, which means every reference to the secret is replaced
with its value
</p>