準備作業:
需要先把react專案的組態檔解構出來
組態檔有:config和scripts
操作指令:npm run eject 或 yarn eject
注意:最好在啟動專案前就進行解構,這樣遇到的bug會少一些
如果在解構后遇到了問題
問題一:報git錯誤時的操作:git add . -> git commit -m 'init' -> yarn eject
問題二:報缺少babel包---報哪個包的缺失就安裝哪個包:yarn add 包名 --save
關閉eslint:
1.方法一
找到config目錄下的webpack.config.js檔案注釋關于eslint的匯入和rules規則
!disableESLintPlugin &&
new ESLintPlugin({
// Plugin options
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
context: paths.appSrc,
cache: true,
cacheLocation: path.resolve(
paths.appNodeModules,
'.cache/.eslintcache'
),
// ESLint class options
cwd: paths.appPath,
resolvePluginsRelativeTo: __dirname,
baseConfig: {
extends: [require.resolve('eslint-config-react-app/base')],
rules: {
...(!hasJsxRuntime && {
'react/react-in-jsx-scope': 'error',
}),
},
},
}),
1.方法二
在package.json中的eslintConfig內添加關于rules的代碼
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"rules": {
"no-undef": "off",
"no-restricted-globals": "off",
"no-unused-vars": "off"
}
}
注意:
更改配置后一定要重啟: npm start 或 yarn start
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/263842.html
標籤:其他
上一篇:逐行解釋JS防抖及防抖的使用
