新手问下,请问 nextjs + antd 脚手架有没有手把手教学啊?

2023-03-20 10:18:03 +08:00
 Jtyczc

纯新手,有个报错大佬们帮忙看下:

error - /Users/victor/IdeaProjects/next-elite-admin-web/node_modules/antd/es/form/Form.js:9
import classNames from 'classnames';
^^^^^^

SyntaxError: Cannot use import statement outside a module

应该是这行代码报错了: import { FilterValue, SorterResult, TablePaginationConfig, } from 'antd/es/table/interface'

我上网查了下,貌似从零建立一个项目好像很多搭配,没有脚手架直接让我业务代码开发吗

1739 次点击
所在节点    程序员
5 条回复
dawnven
2023-03-20 10:34:52 +08:00
不知 antdesign pro 能不能满足你
cheerxl
2023-03-20 11:24:51 +08:00
@dawnven antd pro 都和 umi 绑定了,肯定不合适
hlwjia
2023-03-20 11:39:36 +08:00
duan602728596
2023-03-20 13:00:44 +08:00
nextjs 会将 node_modules 中的模块使用 require 加载,import 出现在 commonjs 中,需要将 antd 编译打包
修改 next.config.js 文件如下:

module.exports = {
webpack(config, options) {
/* 将 antd 打包到服务端生成的文件中 */
if (options.isServer) {
const endIndex = config.externals.length - 1;
const externalsFunc = config.externals[endIndex];

config.externals[endIndex] = function(ctx, callback) {
if (/(antd|rc-|@ant-design)/i.test(ctx.request)) {
return callback();
}

return externalsFunc(ctx, callback);
};
}
};
kongkx
2023-03-20 13:09:49 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/925445

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX