Next.js: Support next.config.babel.js

Created on 7 Sep 2017  路  4Comments  路  Source: vercel/next.js

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior


It'd be nice to support config files with Babel syntax, e.g., as next.config.babel.js a la Webpack.

Current Behavior


next.config.babel.js isn't picked up, and next.config.js doesn't seem to support syntax enabled by .babelrc.

Steps to Reproduce (for bugs)


  1. Use Babel-enabled syntax in next.config.js or try next.config.babel.js.

Context


We are all used to modern JavaScript features when writing our JS. Some features would be especially useful, e.g., object spread operator.

Your Environment


| Tech | Version |
|---------|---------|
| next | 3.2.1 |
| node | 8.4.0 |
| OS | macOS Sierra 10.12.6 (16G29) |
| browser | Google Chrome 60.0.3112.113 (Official Build) (64-bit) |

Most helpful comment

There is a real need in combination with static export. We are currently trying to fetch a list of blog posts from Contentful and add a route for each one of them to the staticExportMap. We already have a module abstracting Contentful that we use in our pages, but we cannot use it in next.config.js because it uses imports. So the only workaround is to change this module (and the modules it imports) to use require instead of import, which is really ugly.

All 4 comments

Alot of people mentioned this trick:

//next.config.js
require('babel-register');
module.exports = require('./next.config.es6.js');

//next.config.es6.js
import blahblah...

Ideally you would want to compile ES6 with Babel beforehand.

There is currently no need to transpile the config file.

There is a real need in combination with static export. We are currently trying to fetch a list of blog posts from Contentful and add a route for each one of them to the staticExportMap. We already have a module abstracting Contentful that we use in our pages, but we cannot use it in next.config.js because it uses imports. So the only workaround is to change this module (and the modules it imports) to use require instead of import, which is really ugly.

@denisw I have exactly the same problem.
Also fetching data from contentful and generate dynamic pages with it.
Any insight on this would be helpful
The project I'm working on is private.
But I used similar config on my blog https://github.com/schoenwaldnils/blog

| Tech | Version |
|---------|---------|
| next | 5.0.1-canary-10 |
| node | 8.9.1 |

Was this page helpful?
0 / 5 - 0 ratings

Related issues

formula349 picture formula349  路  3Comments

irrigator picture irrigator  路  3Comments

renatorib picture renatorib  路  3Comments

wagerfield picture wagerfield  路  3Comments

flybayer picture flybayer  路  3Comments