如何撰写next.config.js文件

JavaScript React.js

LEY小卤蛋

2020-03-24

我正在尝试为我的下一个应用程序添加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: '/'
    }
  })
 }
})

有人可以帮忙吗?

第3296篇《如何撰写next.config.js文件》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
伽罗理查德 2020.03.24

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android