React应用程序的生产版本缺少几个文件夹

时间:2019-12-12 13:43:20

标签: reactjs npm build yarn antd

我有一个使用React ant设计框架构建的应用程序。该应用程序在我的本地环境中运行良好。问题是当我进行构建并将其部署到服务器上时,构建文件夹中缺少几个文件夹,导致应用程序无法运行。这就是代码结构的样子

Code folder structure

构建代码后,将给出以下结构

build folder structure

如您所见,我缺少一个文件夹,结果出现以下错误

console error

路由器代码为

<Switch>
    <Route
      exact
      path={`${url}`}
      component={asyncComponent(() => import("../AdminHome"))}
    />
    <Route
      exact
      path={`${url}/edit-role`}
      component={asyncComponent(() => import("../AdminHome/EditRole"))}
    />
    <Route
      exact
      path={`${url}/clients`}
      component={asyncComponent(() => import("../MdmClient/home"))}
    />
    <Route
      exact
      path={`${url}/clients/edit`}
      component={asyncComponent(() => import("../MdmClient/EditClient"))}
    />
    <Route
      exact
      path={`${url}/clients/add`}
      component={asyncComponent(() => import("../MdmClient/AddClient"))}
    />
  </Switch>

代码asyncComponent是

export default function asyncComponent(importComponent) {
class AsyncFunc extends Component {
    constructor(props) {
        super(props);
        this.state = {
            component: null
        };
    }

    UNSAFE_componentWillMount() {
        Nprogress.start();
    }

    componentWillUnmount() {
        this.mounted = false;
    }

    async componentDidMount() {
        this.mounted = true;
        const { default: Component } = await importComponent();
        Nprogress.done();
        if (this.mounted) {
            this.setState({
                component: <Component {...this.props} />
            });
        }
    }

    render() {
        const Component = this.state.component || <div />;
        return (
            <ReactPlaceholder type="text" rows={7} ready={Component !== null}>
                {Component}
            </ReactPlaceholder>
        );
    }
}
return AsyncFunc;
}

我被困了一个星期,尝试了所有可以在互联网上找到的东西,但没有任何效果。任何帮助表示赞赏。

.gitignore下面的代码

# See https://help.github.com/articles/ignoring-files/ for more about 
ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

0 个答案:

没有答案