.babelrc文件下,按照antd文檔按需加載加入;
{
? ? "presets": ["next/babel"],
? "plugins": [
? ? [? "import",
? ? ? ? {
? ? ? ? ? "libraryName": "antd",
? ? ? ? ? "style": "css"
? ? ? ? }]
? ]
? }
next.config.js文件里面加入
webpack(config, { isServer }) {
? ? if (isServer) {
? ? ? const antStyles = /antd\/.*?\/style\/css.*?/
? ? ? const origExternals = [...config.externals]
? ? ? config.externals = [
? ? ? ? (context, request, callback) => {
? ? ? ? ? if (request.match(antStyles)) return callback()
? ? ? ? ? if (typeof origExternals[0] === 'function') {
? ? ? ? ? ? origExternals[0](context, request, callback)
? ? ? ? ? } else {
? ? ? ? ? ? callback()
? ? ? ? ? }
? ? ? ? },
? ? ? ? ...(typeof origExternals[0] === 'function' ? [] : origExternals),
? ? ? ]
? ? ? config.module.rules.unshift({
? ? ? ? test: antStyles,
? ? ? ? use: 'null-loader',
? ? ? })
? ? }
? ? return config
? }