[英]How to compose the next.config.js file
我正在嘗試為我的下一個應用程序添加 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: '/'
}
})
}
})
任何人都可以幫忙嗎?
這是一個老問題,但看到人們正在尋找這個問題,我想我應該發布一個答案。 我建議使用https://github.com/cyrilwanner/next-compose-plugins它是一個非常簡單的 API,而且更簡潔。 希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.