// in next.config.js
module.exports = {
entry: "./entry",
};
// or
module.exports = {
entry: {
client: "./entry/client",
server: "./entry/server",
},
};
这是目前的解决方法:
在pages/_document.js
添加import "../entry/server.js";
并将下面的代码添加到next.config.js
。
module.exports = {
webpack: (config) => {
const entryFactory = config.entry;
config.entry = () => (
entryFactory()
.then((entry) => {
entry["main.js"] = [
"./entry/client.js",
...entry["main.js"],
];
return entry;
})
);
return config;
},
};
上面的代码创建了一个嵌套的entry
数组。 这是需要的,还是应该有传播:
module.exports = {
webpack: (config) => {
const entryFactory = config.entry;
config.entry = () => (
entryFactory()
.then((entry) => {
entry["main.js"] = [
"./entry/client.js",
...entry["main.js"], // <-- Flatten the array?
];
return entry;
})
);
return config;
},
};
是的@jcheroske您的建议是正确的。
我会更新原始代码。
我正在关闭这个问题。
最有用的评论
这是目前的解决方法:
在
pages/_document.js
添加import "../entry/server.js";
并将下面的代码添加到next.config.js
。