Skip to content

Instantly share code, notes, and snippets.

@remy
Created July 18, 2017 18:37
Show Gist options
  • Save remy/6bb7beccc6355cafa7eac64f46467c66 to your computer and use it in GitHub Desktop.
Save remy/6bb7beccc6355cafa7eac64f46467c66 to your computer and use it in GitHub Desktop.
Next.js configuration for dotenv and custom servers.
const webpack = require('webpack');
require('dotenv').config({
path: process.env.NODE_ENV === 'production' ? '.env.production' : '.env'
});
module.exports = {
webpack: config => {
const env = Object.keys(process.env).reduce((acc, curr) => {
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
return acc;
}, {});
config.plugins.push(new webpack.DefinePlugin(env));
return config;
}
};
@kumarabhirup
Copy link

For some reason that didn't work for me in Next 9

@remy
Copy link
Author

remy commented Sep 6, 2019

This is how I'm doing it with latest next:

webpack: config => {
  config.plugins.push(
    new webpack.EnvironmentPlugin({ PUBLIC_URL: '/static' })
  );
  return config;
}

@NLStom
Copy link

NLStom commented Jan 2, 2021

what is this for?

When I push this repo to Vercel, I got
Uncaught (in promise) Error: Request failed with status code 405

https://vl-ounge.vercel.app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment