不暴露 create react app 的webpack配置下,修改webpack配置

使用 react-app-rewired

react-app-rewired 传送门

安装 react-app-rewired

npm install react-app-rewired --save-dev

项目根目录创建 onfig-overrides.js

/* config-overrides.js */
module.exports = function override(config, env) {
  //do stuff with the webpack config...
  return config;
}

进入package.json 修改命令

  "scripts": {
-   "start": "react-scripts start",
+   "start": "react-app-rewired start",
-   "build": "react-scripts build",
+   "build": "react-app-rewired build",
-   "test": "react-scripts test --env=jsdom",
+   "test": "react-app-rewired test --env=jsdom",
    "eject": "react-scripts eject"
}

onfig-overrides.js文件里添加webpack配置

使用react-app-rewire-less添加Less

react-app-rewire-less传送门

你可能感兴趣的:(react,react.js,webpack,javascript)