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

進(jìn)入config/paths.js查找appHtml及appIndexJs字段添加以下內(nèi)容:

src文件結(jié)構(gòu)如下:

進(jìn)入config/webpack.config.js施工部分如下:

4

5

6

7

8
運(yùn)行
yarn build


如果出現(xiàn)了Cannot read property 'filter' of undefined報錯

解決辦法如下:
在config/webpack.config.js文件下找到ManifestPlugin函數(shù),注釋掉generate參數(shù)或者取消entrypoints這個值的傳遞
ManifestPlugin這個插件的作用是生成一份.json的文件,通過該文件的映射關(guān)系可以讓我們知道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,
// };
// },
}),