将webpack.config.js放置在create-react-app项目中的位置

时间:2019-10-07 12:11:52

标签: javascript reactjs webpack create-react-app

已指示我在webpack.config.js文件中放入一些说明。 但是,在我的create-react-app项目中,找不到该文件。 目前,关于StackOverFlow的可用答案要求弹出项目,我认为这会破坏我的项目。 是否可以在create-react-app项目中使用webpack.config.js而不会弹出? webpack.config.js文件在哪里?还是我应该放在哪里?

3 个答案:

答案 0 :(得分:3)

您可能想使用Craco。它允许您覆盖create-react-app配置。除此之外,public class ChefsBoxRepository { private MutableLiveData<List<RawMaterialsEntity>> searchResults = new MutableLiveData<>(); private LiveData<List<RawMaterialsEntity>> allMaterials; private RawMaterialsDao rawMaterialDao; //public constructor public ChefsBoxRepository(Application application) { ChefsBoxRoomDataBase db; db = ChefsBoxRoomDataBase.getDatabase(application); rawMaterialDao = db.rawMaterialDao(); allMaterials = rawMaterialDao.getAllMaterials(); } //used by the view model public LiveData<List<RawMaterialsEntity>> getAllMaterials() { return allMaterials; } //used by the view model public MutableLiveData<List<RawMaterialsEntity>> getSearchResults() { return searchResults; } public void insertMaterial(RawMaterialsEntity newMaterial) { InsertAsyncTask task = new InsertAsyncTask(rawMaterialDao); task.execute(newMaterial); } public void costPerGm(){ CostPerGmAsyncTask task = new CostPerGmAsyncTask(rawMaterialDao); task.execute(); } public void totalCost(){ TotalCostAsyncTask task = new TotalCostAsyncTask(rawMaterialDao); task.execute(); } public void deleteMaterial(String name) { DeleteAsyncTask task = new DeleteAsyncTask(rawMaterialDao); task.execute(name); } public void findMaterial(String name) { QueryAsyncTask task = new QueryAsyncTask(rawMaterialDao); task.delegate = this; task.execute(name); } public void findMaterialById(int id) { QueryAsyncTask2 task = new QueryAsyncTask2(rawMaterialDao); task.delegate = this; task.execute(id); } private void asyncFinished(List<RawMaterialsEntity> results) { searchResults.setValue(results); } //QueryAsyncTask for calling items from database private static class QueryAsyncTask extends AsyncTask<String, Void, List<RawMaterialsEntity>> { private RawMaterialsDao asyncTaskDao; private ChefsBoxRepository delegate = null; QueryAsyncTask(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected List<RawMaterialsEntity> doInBackground(final String... params) { return asyncTaskDao.findMaterial(params[0]); } @Override protected void onPostExecute(List<RawMaterialsEntity> result) { delegate.asyncFinished(result); } } //QueryAsyncTask for calling items from database private static class QueryAsyncTask2 extends AsyncTask<Integer, Void, List<RawMaterialsEntity>> { private RawMaterialsDao asyncTaskDao; private ChefsBoxRepository delegate = null; QueryAsyncTask2(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected List<RawMaterialsEntity> doInBackground(final Integer... params) { return asyncTaskDao.findMaterialById(params[0]); } @Override protected void onPostExecute(List<RawMaterialsEntity> result) { delegate.asyncFinished(result); } } //InsertAsyncTask for inserting items to the database private static class InsertAsyncTask extends AsyncTask<RawMaterialsEntity, Void, Void> { private RawMaterialsDao asyncTaskDao; InsertAsyncTask(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected Void doInBackground(final RawMaterialsEntity... params) { asyncTaskDao.insertMaterial(params[0]); return null; } } //DeleteAsyncTask for deleting items from the database private static class DeleteAsyncTask extends AsyncTask<String, Void, Void> { private RawMaterialsDao asyncTaskDao; DeleteAsyncTask(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected Void doInBackground(final String... params) { asyncTaskDao.deleteMaterial(params[0]); return null; } } //CostPerGmAsyncTask for dividing the materialCost on the materialWeight private static class CostPerGmAsyncTask extends AsyncTask<Void, Void, Void> { private RawMaterialsDao asyncTaskDao; CostPerGmAsyncTask(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected Void doInBackground(Void... voids) { asyncTaskDao.divide(); return null; } } //TotalCostAsyncTask for dividing the materialCost on the materialWeight private static class TotalCostAsyncTask extends AsyncTask<Void, Void, Void> { private RawMaterialsDao asyncTaskDao; TotalCostAsyncTask(RawMaterialsDao dao) { asyncTaskDao = dao; } @Override protected Void doInBackground(Void... voids) { asyncTaskDao.totalCost(); return null; } } } 是一个不错的选择,并且它不会破坏您的应用程序

答案 1 :(得分:2)

答案 2 :(得分:1)

create-react-app对您隐藏配置文件。如果要修改它们,则必须运行npm run eject。这会将它们放置在config/文件夹下。

在执行此操作之前,请先阅读此内容,因为这不是可逆的操作:https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject