Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我的模块未被带有React.lazy的webpack typescript分块_Reactjs_Typescript_Lazy Loading_React Router Dom_Webpack 4 - Fatal编程技术网

Reactjs 我的模块未被带有React.lazy的webpack typescript分块

Reactjs 我的模块未被带有React.lazy的webpack typescript分块,reactjs,typescript,lazy-loading,react-router-dom,webpack-4,Reactjs,Typescript,Lazy Loading,React Router Dom,Webpack 4,我使用动态路由(react-router-dom),如下所述 路线 const Home = React.lazy(() => import("../../home")); const Page2Component = React.lazy(() => import("../../page2Component")); const ROUTES: RoutesInterface[] = [ { id: &qu

我使用动态路由(react-router-dom),如下所述

路线

const Home = React.lazy(() => import("../../home"));

const Page2Component = React.lazy(() => import("../../page2Component"));

const ROUTES: RoutesInterface[] = [
    
    {
        id: "home",
        to: HOME_URL,
        exact: true,
        type: RouteType.ROUTE,
        Component: Home,
    },
    {
        id: "page_2",
        to: PAGE_2_URL,
        exact: true,
        type: RouteType.ROUTE,
        // @ts-ignore
        Component: Page2Component
    }]
路由器映射组件

import ROUTES from "./ducks/routes";

export default class Routes extends React.Component<RoutesPropsInterface> {
    constructor(props: RoutesPropsInterface) {
        super(props);
    }

    public render(): JSX.Element {
        const { meta, analytics } = this.props;
        const componentProps = {
            analytics,
            appmeta: meta,
        };
        return (
            <Router>
                <Suspense fallback={<span>Loading...</span>}>
                    <NavigationWithRouter />
                    <Switch>
                        {ROUTES.map(({ id, to, from, type, exact, Component }: RoutesInterface) =>
                            type === RouteType.ROUTE ?
                            <Route
                                key={id}
                                path={to}
                                exact={exact}
                                render={(routeProps: RouteComponentProps) => <Component
                                    {...componentProps}
                                    {...routeProps}
                                />}
                            /> :
                            <Redirect
                                key={id}
                                from={from}
                                to={to}
                                exact={exact}
                            />
                        )}
                    </Switch>
                </Suspense>
            </Router>
        );
    }
}
从“/ducks/ROUTES”导入路由;
导出默认类路由扩展React.Component{
构造器(道具:RoutesPropsInterface){
超级(道具);
}
public render():JSX.Element{
const{meta,analytics}=this.props;
常量组件props={
分析,
appmeta:meta,
};
返回(
{ROUTES.map({id,to,from,type,exact,Component}:routeInterface)=>
类型===RouteType.ROUTE?
}
/> :
)}
);
}
}
当我在映射之前调试路由时,我可以看到它即将映射延迟加载的组件

然而,当我检查最终的捆绑代码时,它只包含了我的
vendors
srcmain

为什么懒惰的邦德林在我的情况下不在这里工作?由于webpack4支持lazy配置,因此没有其他配置

解决方案

  • 使用
    module:“commonjs
    时,需要对我的tsconfig使用
    module:“esnext”

  • 其他一些(旧的路由文件)也被导入,尽管我没有在我的文件Web包中调用该导入,而是捆绑该文件并忽略我的延迟路由


  • 绝对救生员,你应该把“解决方案”作为答案。绝对救生员,你应该把“解决方案”作为答案。