在github页面上使用Gatsby部署react-p5不会显示在prod中,但在本地运行良好
回购: 部署: 我有盖茨比和react-p5 我还使用了在github页面上使用Gatsby部署react-p5不会显示在prod中,但在本地运行良好,gatsby,p5.js,Gatsby,P5.js,回购: 部署: 我有盖茨比和react-p5 我还使用了@loadable/component来解决盖茨比找不到窗口对象的问题 它在本地运行良好,但部署时p5草图不存在 我的主要分支是dev,因为master在github页面中用于构建部署 我在package.json中有一个部署脚本: "deploy": "gatsby build && gh-pages -d public -b master", 我在github中的部署分支设置为m
@loadable/component
来解决盖茨比找不到窗口对象的问题
它在本地运行良好,但部署时p5草图不存在
我的主要分支是dev,因为master在github页面中用于构建部署
我在package.json中有一个部署脚本:
"deploy": "gatsby build && gh-pages -d public -b master",
我在github中的部署分支设置为master
我还有一个gatsby-node.js,我认为这解决了gatsby和窗口对象的问题:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-p5/,
use: loaders.null(),
},
],
},
})
}
}
但是,当我部署设置为背景的草图时,它丢失了,我得到了以下错误:
webpack-runtime-158cdcd6eecd3346d680.js:1 Failed to load resource: the server responded with a status of 404 ()
framework-83e11af5cf111be5ad89.js:1 Failed to load resource: the server responded with a status of 404 ()
app-dd1630b327c4af5b0e12.js:1 Failed to load resource: the server responded with a status of 404 ()
styles-407fe62976dc5310c43e.js:1 Failed to load resource: the server responded with a status of 404 ()
component---src-pages-index-js-3b0dffb8368984a5863f.js:1 Failed to load resource: the server responded with a status of 404 ()
/page-data/index/page-data.json:1 Failed to load resource: the server responded with a status of 404 ()
/page-data/app-data.json:1 Failed to load resource: the server responded with a status of 404 ()
webpack-runtime-158cdcd6eecd3346d680.js:1 Failed to load resource: the server responded with a status of 404 ()
Index.js:
import React from "react"
import { Link } from "gatsby"
import Layout from '../components/Layout'
import loadable from "@loadable/component"
const Sketch = loadable(() => import("react-p5"))
const Background = (props) => {
const setup = (p5, canvasParentRef) => {
canvas = p5.createCanvas(p5.windowWidth, p5.windowHeight /*, p5.WEBGL*/).parent(canvasParentRef)
...
}
const draw = (p5) => {
...
};
return <Sketch windowResized={windowResized} setup={setup} draw={draw} />
}
const IndexPage = () => {
return (
<div>
<Background />
<Layout>
...
</Layout>
</div>
)
}
export default IndexPage
从“React”导入React
从“盖茨比”导入{Link}
从“../components/Layout”导入布局
从“@loadable/component”导入可加载
常量草图=可加载(()=>导入(“react-p5”))
常量背景=(道具)=>{
常量设置=(p5,canvasParentRef)=>{
canvas=p5.createCanvas(p5.windowWidth,p5.windowHeight/*,p5.WEBGL*/).parent(canvasParentRef)
...
}
常量绘制=(p5)=>{
...
};
返回
}
常量索引页=()=>{
返回(
...
)
}
导出默认索引扩展