1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-02-26 04:22:36 +01:00
developer-roadmap/next.config.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

const path = require('path');
2019-11-16 16:11:08 +04:00
const fs = require('fs');
2019-08-24 18:34:46 +04:00
const withSass = require('@zeit/next-sass');
2019-09-04 15:27:00 +04:00
const withCSS = require('@zeit/next-css');
const rehypePrism = require('@mapbox/rehype-prism');
2019-11-01 09:28:05 +04:00
const withMDX = require('@next/mdx')({
extension: /\.(md|mdx)?$/,
options: {
rehypePlugins: [rehypePrism],
},
});
2019-11-16 16:11:08 +04:00
const { getPathMap } = require("./scripts/path-map");
2019-10-18 23:40:37 +04:00
2019-11-16 16:11:08 +04:00
/**
* Loads the configuration for the given environment
* @param env
* @returns {*}
*/
const loadConfig = (env = 'dev') => {
const configPath = `./config/${env}.json`;
if (!fs.existsSync(configPath)) {
console.log(`Config file not found: ${configPath}`);
process.exit(1);
}
2019-11-16 15:21:40 +04:00
2019-11-16 16:11:08 +04:00
console.log(`Config file found: ${configPath}`);
// @todo stringify the values for webpack - it doesn't understand objects
return require(configPath);
};
2019-11-01 09:28:05 +04:00
2019-11-16 16:11:08 +04:00
const options = {
exportPathMap: getPathMap(),
env: loadConfig(process.env.NODE_ENV),
pageExtensions: ['jsx', 'js', 'mdx', 'md'],
2019-09-04 16:32:25 +04:00
webpack(config, options) {
2019-11-02 12:45:15 +04:00
// // Transforms SVGs to components
2019-09-04 16:32:25 +04:00
config.module.rules.push({
2019-11-02 12:45:15 +04:00
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.resolve.modules.push(path.resolve('./'));
2019-11-08 01:32:01 +04:00
// Allow loading images and fonts
2019-11-02 12:45:15 +04:00
config.module.rules.push({
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/,
2019-09-04 16:32:25 +04:00
use: {
loader: 'url-loader',
options: {
limit: 100000,
},
},
});
return config
},
2019-11-01 09:28:05 +04:00
};
let nextConfig = withSass(options);
nextConfig = withCSS(nextConfig);
nextConfig = withMDX(nextConfig);
module.exports = nextConfig;