从react-loadable命名webpack块 [英] Name webpack chunks from react-loadable

查看:621
本文介绍了从react-loadable命名webpack块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在项目中成功添加了react-loadable库来启用代码拆分,我发现的唯一问题是webpack生成的块没有命名,而是被赋予了整数名称.

I've successfully added react-loadable library in my project to enable code splitting, the only problem I've found is that the chunks generated by webpack are not named, they are given integer names.

我的可用于响应加载的代码是

My code for react-loadable use is

const AppRootLoadable = Loadable({
  loader: () => import(/* webpackChunkName: "app" */ './App'),
  loading: () => null,
  render(loaded) {
    const Component = loaded.default;
    return <Component />;
  },
});

我添加了评论,以告诉Webpack 3我希望将此块命名为app.我做错了什么吗?

I've added the comment to tell webpack 3 that I want this chunk to be named app. Have I done something wrong?

推荐答案

好,四天后我找到了解决方案.我需要将chunkFilename行添加到我的webpack配置中:

Ok, after 4 days I found the solution. I needed to add the chunkFilename line to my webpack config:

output: {
  path: path.join(__dirname, './../public'),
  filename: 'bundle.js',
  publicPath: '/',
  chunkFilename: '[name].[chunkhash].js'
},

然后它起作用.我在 webpack github页面

这篇关于从react-loadable命名webpack块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆