Skip to content

Instantly share code, notes, and snippets.

@abedzantout
Last active September 20, 2019 20:45
Show Gist options
  • Save abedzantout/fe8aab9db7653e44d5dac16383343bf0 to your computer and use it in GitHub Desktop.
Save abedzantout/fe8aab9db7653e44d5dac16383343bf0 to your computer and use it in GitHub Desktop.
Next Config Final
// next.config.js
const withCSS = require('@zeit/next-css');
const path = require('path');
const Dotenv = require('dotenv-webpack');
const { generateAllArticles } = require('./utils/helpers');
const next_config = {
webpack: config => {
config.plugins = config.plugins || [];
config.plugins = [
...config.plugins,
// Read the .env file
new Dotenv({
path: path.join(__dirname, '.env'),
systemvars: true
})
];
return config;
},
// New exportPathMap function added
// This will allow us to export all available blog posts when building and exporting our website
exportPathMap: async () => {
const articles = await generateAllArticles();
const insights = articles.reduce(
(pages, entry) =>
Object.assign({}, pages, {
[`/post/${entry.slug}`]: {
page: '/post',
query: { post: entry.slug }
}
}),
{}
);
const pages = {
'/': { page: '/' },
'/post': { page: '/post' }
};
return Object.assign({}, pages, insights);
}
};
module.exports = withCSS({ ...next_config });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment