我使用带有与-antd样板的Nextjs,它附带一个预配置的next.config.js
文件。
就像这样;
/* eslint-disable */
const withCss = require('@zeit/next-css')
// fix: prevents error when .css files are required by node
if (typeof require !== 'undefined') {
require.extensions['.css'] = (file) => {}
}
module.exports = withCss()
我想编辑这个配置文件并添加像exportPathMap
这样的配置。
如下所示:
module.exports = {
exportPathMap: function () {
return {
'/': { page: '/' },
'/about': { page: '/about' },
'/p/hello-nextjs': { page: '/post', query: { title: 'Hello Next.js' } },
'/p/learn-nextjs': { page: '/post', query: { title: 'Learn Next.js is awesome' } },
'/p/deploy-nextjs': { page: '/post', query: { title: 'Deploy apps with Zeit' } }
}
}
}
但是我不知道如何在不破坏withCss
插件的情况下实现它,请帮助。
发布于 2019-01-16 07:12:53
解决这个问题的方法是认识到,我使用的下一个插件,如@zeit/next-css
,会使用更多作为插件对象传递的下一个配置。
来自@zeit/next-css
插件的片段。
module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}
因此,通过计算,我将exportPathMap
作为withCss
中的一个对象。
module.exports = withCss({
exportPathMap: function() {
return {
'/': {page: '/'},
'/sevices': {page: '/services'},
'/about': {page: '/about'},
'/contacts': {page: '/contacts'},
}
}
})
就这样!
https://stackoverflow.com/questions/54191888
复制