繁体   English   中英

使用webpack 3进行react-loadable和服务器端渲染

[英]react-loadable and server side rendering with webpack 3

我正在为react-router-v4使用react-loadable ,我想做服务器端渲染。 当然,在服务器端,我不需要延迟加载,所以我开始使用react-loadable ,因为它表示可以在import-inspector babel插件的帮助下与服务器一起使用。

但是不幸的是,我的服务器控制台require.ensure is not a function出现错误,这require.ensure is not a function ,这导致了客户端的重新渲染,并且我失去了服务器端渲染的所有好处。

在我使用react-router-v3并将getComponentimport一起使用之前,没有任何问题。

这是我的路线配置。

export default [
    {
        component: Root,
        routes: [
            {
                path: '/',
                component: Loadable({
                    loader: () => import('./Parent.jsx'),
                    loading: () => <div>Loading...</div>
                }),
                routes: [
                    {
                        path: '/',
                        exact: true,
                        component: Loadable({
                            loader: () => import('./Child.jsx'),
                            loading: () => <div>Loading...</div>
                        })
                    }
                ]
            }
        ]
    }
];

这是我的.babelrc

{
    presets : [["es2015", {modules: false}], "react", "stage-2", "stage-3"],
    plugins: [ 
        "transform-runtime", 
        "syntax-async-functions", 
        "dynamic-import-webpack"
    ],
    env: {
        node: {
            plugins: [
                ["import-inspector", {
                  "serverSideRequirePath": true,
                  "webpackRequireWeakId": true,
                }],
                ["babel-plugin-webpack-alias", {
                    "config": "webpack/server.js",
                    "findConfig": true
                }]
            ]
        }
    }
}

在客户端上,它可以完美运行,唯一的错误是标记校验和差异错误。 这应该如何工作?

提前致谢!

尝试将其添加到babel或babel加载程序

“动态导入节点”,

那是来自airbnb

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM