Skip to content

Instantly share code, notes, and snippets.

@timneutkens
Forked from pkellner/next.config.js
Last active February 15, 2019 14:19
Show Gist options
  • Save timneutkens/0a60e823d37cd67458cfb307e9e25adf to your computer and use it in GitHub Desktop.
Save timneutkens/0a60e823d37cd67458cfb307e9e25adf to your computer and use it in GitHub Desktop.
require('dotenv').config();
const withCSS = require('@zeit/next-css');
const path = require('path');
const Dotenv = require('dotenv-webpack');
const withImages = require('next-images');
const withTypescript = require('@zeit/next-typescript');
const withOffline = require('next-offline');
const {PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD} = require('next/constants')
//const isProd = process.env.NODE_ENV === 'production';
// RESTURL_SPEAKERS_PROD=https://www.siliconvalley-codecamp.com/rest/speakers/ps
// RESTURL_SPEAKERS_DEV=http://localhost:4000/speakers
// RESTURL_SPEAKER_PROD=https://www.siliconvalley-codecamp.com/rest/Speakers
// RESTURL_SPEAKER_DEV=/speakers
/* Without CSS Modules, with PostCSS */
module.exports = (phase) => {
const isDev = phase === PHASE_DEVELOPMENT_SERVER
const isProd = phase === PHASE_PRODUCTION_BUILD
const isStaging = process.env.STAGING === '1'
const env = {
RESTURL_SPEAKERS: (() => {
if(isDev) return '/speakers'
if(isProd) return 'https://www.siliconvalley-codecamp.com/rest/speakers/ps'
return 'default here'
})(),
RESTURL_SPEAKER: (() => {
if(isDev) return '/speakers'
if(isProd) return 'https://www.siliconvalley-codecamp.com/rest/Speakers'
return 'default here'
})()
}
return withTypescript(
withCSS(
withImages(
withOffline({
env,
//assetPrefix: isProd ? 'http://d30k733rzexkhf.cloudfront.net' : '',
inlineImageLimit: 16384,
serverRuntimeConfig: {
// Will only be available on the server side
},
publicRuntimeConfig: {
BASEURL_DEFAULT: 'https://www.siliconvalley-codecamp.com',
RESTURL_SPEAKERS_DEFAULT: 'https://www.siliconvalley-codecamp.com/rest/speakers/ps',
RESTURL_SPEAKER_DEFAULT: 'https://www.siliconvalley-codecamp.com/rest/speaker',
RESTURL_SESSIONS_DEFAULT: 'https://www.siliconvalley-codecamp.com/rest/sessions',
RESTURL_ISLOGGEDIN_DEFAULT: 'https://www.siliconvalley-codecamp.com/rpc/account/isLoggedInMobileApp',
LOGINAUTH_URL_DEFAULT: 'https://www.siliconvalley-codecamp.com/rpc/account/Login',
LOGOUT_URL_DEFAULT: 'https://www.siliconvalley-codecamp.com/rpc/account/LogOutMobileApp',
ISLOGGEDIN_NO_DEFAULT: 'https://www.siliconvalley-codecamp.com/rpc/Account/IsLoggedIn',
PUBLIC_URL: ''
},
webpack(config, options) {
config.plugins = config.plugins || [];
config.plugins = [
...config.plugins,
// Read the .env file
new Dotenv({
path: path.join(__dirname, '.env'),
systemvars: true
})
];
return config;
}
})
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment