以前我的项目设置是
public
.next
src
pages
components
assets
next.config.js
这个方法工作得很好,但我将结构改为如下
public
src
client
next.config.js
jsconfig.json
pages
components
assets
server
index.js
现在这个不起作用了。我收到错误的Couldn't find a
pagesdirectory. Please create one under the project root
这是我更新的next.config.js
const withPlugins = require("next-compose-plugins");
const optimizedImages = require("next-optimized-images");
const withPWA = require("next-pwa");
module.exports = withPlugins(
[optimizedImages],
[
withPWA({
pwa: {
dest: "public",
},
}),
],
{
distDir: '../../dist/client',
}
);
用于绝对导入(从‘components/ Button’导入按钮)
jsconfig.json
{
"compilerOptions": {
"baseUrl": "client/"
}
}
package.json
"scripts": {
"dev:client": "nextjs src/client",
"dev:server": "node src/server --out-dir dist/server --source-maps --watch",
"dev": "dotenv -e .env.development yarn dev:client & yarn dev:server",
"build": "yarn build:client && yarn build:server",
"build:client": "dotenv -e .env.production next build src/client",
"build:server": "node src/server --out-dir dist/server --source-maps",
"build:staging": "yarn build:staging:client && yarn build:server",
"build:staging:client": "dotenv -e .env.staging next build src/client",
"start": "next start",
},
.babelrc
{
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
],
"presets": [
"next/babel"
]
}
发布于 2020-05-20 10:22:55
根据官方的NextJs documentation pages文件夹,可以将其移动到src文件夹中。但是像next.config.js和tsconfig.json这样的配置文件应该在根目录中,将它们移动到src将不起作用。公共目录也是如此。
将next.config.js文件移动到根文件夹。
https://stackoverflow.com/questions/61903950
复制相似问题