将workbox-webpack-plugin配置添加到webpack配置中,而无需通过react-app-rewired弹出来添加工作盒injectManifest插件

时间:2020-03-04 13:31:04

标签: reactjs webpack workbox-webpack-plugin

通过config-overrides.js将来自工作箱的injectManifest插件添加到webpack配置中,因为我不想注入我的项目

警告:我是这个新手。

我正在寻找战争,以添加一些配置以将injectManifest插件插入到我的webpack配置中,而不会弹出webpack设置,最后我发现该插件的名称为 react-app-rewired 并且此插件为我提供了一种添加一些配置的方法,但是我知道我如何添加配置,我尝试了一种简单的方法,但是当我尝试朗读 npm start 时出现错误。

const { InjectManifest } = require("workbox-webpack-plugin");

module.exports = function override(config, env) {
   //do stuff with the webpack config...

   config["plugins"].push(

   new InjectManifest({
   swSrc: "./src/sw.js"
  })

);
 return config;
};

但是我在控制台中出现了这样的错误:

> react-gentelella@0.1.0 start /home/fibo/Documents/m_reacjs_tesaa
> react-app-rewired start

Failed to compile.

Cannot read property 'make' of undefined

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-gentelella@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-gentelella@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/fibo/.npm/_logs/2020-03-04T13_10_36_994Z-debug.log

0 个答案:

没有答案