1 回答

TA貢獻1801條經驗 獲得超8個贊
盡管這不是一個共同的目的,但您可以gatsby-node.js通過 Gatsby API ( onPostBuild) 實現(xiàn)這一目標:
const path = require("path")
const fs = require("fs")
exports.onPreInit = () => {
if (process.argv[2] === "build") {
fs.rmdirSync(path.join(__dirname, "dist"), { recursive: true })
fs.renameSync(
path.join(__dirname, "public"),
path.join(__dirname, "public_dev")
)
}
}
exports.onPostBuild = () => {
fs.renameSync(path.join(__dirname, 'public'),
path.join(__dirname, 'dist'), { overwrite: true })
fs.renameSync(
path.join(__dirname, "public_dev"),
path.join(__dirname, "public")
)
}
/dist在上面的示例中,您將在運行gatsby build命令時輸出 in 。
有用的 GitHub 問題:
https://github.com/gatsbyjs/gatsby/issues/18975
https://github.com/gatsbyjs/gatsby/issues/14703
添加回答
舉報