K
K
Kir032019-03-30 21:00:23
JavaScript
Kir03, 2019-03-30 21:00:23

How to properly configure webpack.config and linter?

I want to make for myself a small template for building a project using Webpack. I want to try using react hook, typescript. config looks like this

const path = require("path");
const webpack = require("webpack");

module.exports = {
    entry: "./src/index",
    output: {
        path: path.resolve(__dirname, "public", "build"),
        filename: "bundle.js",
        publicPath: "/build/"
    },

    resolve: {
        extensions: [".ts", ".tsx", ".js", ".json"]
    },

    module: {
        rules: [
            {
                test: /\.(ts|js)x?$/,
                exclude: /node_modules/,
                use: ["babel-loader"]
            }
        ]
    },

    devServer: {
        contentBase: path.join(__dirname, "public"),
        compress: true,
        port: 9000,
        host: "0.0.0.0",
        historyApiFallback: true
    }
};

.babelrc
{
    "presets": [
        "@babel/env",
        "@babel/typescript",
        "@babel/react"
    ],
    "plugins": [
        "@babel/proposal-class-properties",
        "@babel/proposal-object-rest-spread"
    ]
}

.eslintrc
{
  "extends": [
    "react-app",
    "prettier"
  ],
  "rules": {
    "no-console": 2,
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
  },
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "react-hooks",
    "prettier"
  ]
}

tsconfig.json
{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "noFallthroughCasesInSwitch": true,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "noUnusedLocals": true,
        "noImplicitAny": true,
        "target": "es2015",
        "module": "es2015",
        "strict": true,
        "jsx": "react"
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules"]
}

The problem is that with errors in writing the TS code, the project is built, and does not give an error, and the linter with TS does not work either. How to fix it? If you follow the tutorial https://www.typescriptlang.org/docs/handbook/react... then hooks are not supported in this case.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question