美文网首页
react-create-app多页面配置记录

react-create-app多页面配置记录

作者: 我七 | 来源:发表于2020-05-06 15:54 被阅读0次

本次施工react版本为"react": "^16.13.1",
yarn eject
先在public文件中增加所需html文件:

进入config/paths.js查找appHtmlappIndexJs字段添加以下内容:


src文件结构如下:

进入config/webpack.config.js施工部分如下:

4
5
6
7
8
运行yarn build

如果出现了Cannot read property 'filter' of undefined报错

解决办法如下:
config/webpack.config.js文件下找到ManifestPlugin函数,注释掉generate参数或者取消entrypoints这个值的传递
ManifestPlugin这个插件的作用是生成一份.json的文件,通过该文件的映射关系可以让我们知道webpack是如何追踪所有模块并映射到输出bundle中的

//config/webpack.config.js
      new ManifestPlugin({
        fileName: 'asset-manifest.json',
        publicPath: paths.publicUrlOrPath,
        // generate: (seed, files, entrypoints) => {
        //   const manifestFiles = files.reduce((manifest, file) => {
        //     manifest[file.name] = file.path;
        //     return manifest;
        //   }, seed);
        //   const entrypointFiles = entrypoints.main.filter(
        //     fileName => !fileName.endsWith('.map')
        //   );

        //   return {
        //     files: manifestFiles,
        //     entrypoints: entrypointFiles,
        //   };
        // },
      }),

相关文章

网友评论

      本文标题:react-create-app多页面配置记录

      本文链接:https://www.haomeiwen.com/subject/bhxwghtx.html