使用create-react-app創(chuàng)建項(xiàng)目
- 安裝:
npm install -g create-react-app
- 創(chuàng)建項(xiàng)目:
create-react-app my-app
cd my-app
yarn install
yarn start
使用react-app-rewired改寫項(xiàng)目有配置
- 安裝
yarn add react-app-rewired --save-dev
- 在項(xiàng)目根目錄創(chuàng)建
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"
}
在react-app-rewire改寫的項(xiàng)目中配置Sass和Less
1. Sass使用配置
- 安裝
yarn add react-app-rewire-sass-modules sass-loader node-sass -D
- 在
config-overrides.js文件中添加配置
const rewireSass = require('react-app-rewire-sass-modules');
module.exports = function override(config, env) {
config = rewireSass(config, env);
return config;
}
2. Less使用配置
- 安裝
yarn add react-app-rewire-less -D
- 在
config-overrides.js文件中添加配置
const rewireLess = require('react-app-rewire-less');
/* config-overrides.js */
module.exports = function override(config, env) {
config = rewireLess(config, env);
// with loaderOptions
// config = rewireLess.withLoaderOptions(someLoaderOptions)(config, env);
return config;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。