Skip to content

Instantly share code, notes, and snippets.

@Gazzell
Last active January 31, 2024 18:28
Show Gist options
  • Save Gazzell/90bc3c3c26c93e01f7335e1ef3c2e773 to your computer and use it in GitHub Desktop.
Save Gazzell/90bc3c3c26c93e01f7335e1ef3c2e773 to your computer and use it in GitHub Desktop.
React, typescript, use craco to set custom tests paths and import aliases
{
"extends": [
"eslint-config-react-app"
],
"plugins": ["react", "import"],
"rules": {
"import/no-unresolved": "error"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"react": {
"pragma": "React",
"version": "detect"
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
}
}
const path = require("path");
const { ESLINT_MODES } = require("@craco/craco");
const resolve = arg => path.resolve(__dirname, arg)
module.exports = {
webpack: {
alias: {
"~": resolve("src/")
}
},
jest: {
configure: {
moduleNameMapper: {
"^~(.*)$": "<rootDir>/src$1",
},
roots: ["<rootDir>/src/", "<rootDir>/test/"],
testMatch: ["<rootDir>/test/**/?(*.)+(spec|test).[jt]s?(x)"],
setupFilesAfterEnv: "<rootDir>/test/setupTests.ts"
}
},
eslint: {
mode: ESLINT_MODES.file
}
};
"devDependencies": {
"@craco/craco": "^5.6.4",
"@typescript-eslint/parser": "^2.27.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.20.2"
}
{
"extends": "./tsconfig.paths.json", // need to be in a different file
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src/**/*",
"test/**/*" // need to include test dirs
],
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"~/*": [
"src/*"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment