如何撰写next.config.js文件

时间:2018-05-08 13:21:15

标签: javascript node.js reactjs static-site nextjs

我正在尝试为我的下一个应用程序添加sass支持和webpack图像加载器以及对导出路由的支持。我在如何编写配置文件时遇到问题。我不明白如何将sass插件添加到webpack配置中,以及如何编写和导出next.config.js函数。

const fetch = require('isomorphic-unfetch');
var Prismic = require('prismic-javascript');
const withSass = require('@zeit/next-sass')

var apiEndpoint = 'https://apiendpoint/api/v2';

module.exports =

withSass({
    async exportPathMap() {

  const response = await Prismic.getApi(apiEndpoint)
    .then(function (api) {
      return api.query(
        Prismic.Predicates.at('document.type', 'post')
      );
    })
    .then(
      function (response) {
        return response.results
      },
      function (err) {
        console.log('Something went wrong: ', err);
      }
    );

  // tranform the list of posts into a map of pages with the pathname `/post/:id`
  const pages = await response.reduce((pages, post) =>

    Object.assign({}, pages, {
      [`/post/${post.id}`]: {
        page: '/post',
        query: {
          id: post.id
        }
      }
    }), {},

  )


  // combine the map of post pages with the home
  return Object.assign({}, pages, {
    '/': {
      page: '/'
    }
  })
 }
})

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这是一个古老的问题,但是看到人们正在搜索这个问题时,我认为应该发布答案。我建议使用https://github.com/cyrilwanner/next-compose-plugins,这是一个非常简单的API,而且更加简洁。希望这会有所帮助。