Search code examples
webpackwebpack-dev-servereslintwebpack-2create-react-app

integrating eslint-config-react-app to existing project


I try to use eslint-config-react-app in existing project. I literally copy the npm install command from githubpage:

npm install --save-dev eslint-config-react-app [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

then at the root of the project I creacte .eslint file with:

{
  "extends": "react-app"
}

then I start the webpack-dev-server but I get no warnings about unused functions or variables - nothing.

package.json - command I use to start app:

  "scripts": {
    "dev": "webpack-dev-server --config webpack/dev.config.js --hot --inline --progress --colors --history-api-fallback --host 0.0.0.0 --port 8080"
  },

dev.config.js which is placed in webpack subdirectory of project:

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');

module.exports = {
    context: path.resolve(__dirname, '..'),
    entry: [
        'babel-polyfill',
        './src/client.js'
    ],
    output: {
        path: './public',
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        plugins: ['transform-runtime', 'transform-class-properties', 'transform-decorators-legacy'],
                        presets: ['es2015', 'react', 'stage-0']
                    }
                },
            },
            {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'sass-loader']
                })
            },
            {
                test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
                use: "url?limit=10000&mimetype=application/font-woff"
            },
            {
                test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
                use: "url?limit=10000&mimetype=application/font-woff"
            },
            {
                test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
                use: "url?limit=10000&mimetype=application/octet-stream"
            },
            {
                test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
                use: "file"
            },
            {
                test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
                use: "url?limit=10000&mimetype=image/svg+xml"
            },
        ]
    },
    resolve: {
        modules: [
            path.join(__dirname, 'src'),
            'node_modules'
        ],
        alias: {
            components: path.resolve(__dirname, '../src/components'),
            layouts: path.resolve(__dirname, '../src/layouts'),
            pages: path.resolve(__dirname, '../src/pages'),
            api: path.resolve(__dirname, '../src/api'),
        },
        extensions: ['.js', '.jsx']
    },

    devtool: 'inline-source-map',

    plugins: [
        new ExtractTextPlugin({
            filename: 'style.css',
            allChunks: true
        }),
        new CopyWebpackPlugin([
            {from: './static', to: './public/static'}
        ])
    ]
};

Solution

  • I looked up to create-react-app config after eject and what I did is:

    1: npm install --save-dev eslint-loader

    2: Added this to package.json:

    "eslintConfig": {
        "extends": "react-app"
      }
    

    3: Added loader to dev.config.js:

        {
            test: /\.(js|jsx)$/,
            enforce: 'pre',
            exclude: /node_modules/,
            use: 'eslint-loader'
        },
    
    1. No need for .eslintrc file