【发布时间】:2020-08-12 18:13:03
【问题描述】:
在这个问题上,不仅仅是寻找解决方案,我希望你能引导我走向正确的方向。
我正在使用 Next JS。
我的问题出现在生产中,第一次到达像pages/product.tsx 这样的页面可以正常工作。 Capture 2 显示 html 脚本链接格式正确。
但是,刷新同一页面会产生所有 css 或 js 扩展名变成.jsundefined 或.cssundefined。
项目部署在我自己的 digitalocean 服务器上。 当我将同一个项目部署到 Vercel(部署 Next JS 项目的最佳方式)时,它解决了这个问题。
请指导我了解可能导致此问题的原因。
next.config.js
const withCss = require("@zeit/next-css");
const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
});
module.exports = withCss(
withMDX({
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
})
);
.babelrc
{
"env": {
"development": {
"plugins": [
[
"babel-plugin-styled-components",
{ "ssr": true, "displayName": true, "preprocess": false }
]
],
"presets": ["next/babel"]
},
"production": {
"plugins": [
[
"babel-plugin-styled-components",
{ "ssr": true, "displayName": true, "preprocess": false }
]
],
"presets": ["next/babel"]
}
},
"plugins": [
[
"babel-plugin-styled-components",
{ "ssr": true, "displayName": true, "preprocess": false }
]
]
}
【问题讨论】: