2017-03-06 62 views
2

我已經完成了配置我的eslint規則並根據我的規則重構了項目文件。事情是我有一些警告,我可能想離開那裏一段時間。但我的問題是,瀏覽器控制檯上顯示警告,導致發展不可能。Webpack壓制瀏覽器控制檯上的eslint警告

enter image description here

下面,我的WebPack配置:

const path = require('path'); 
const webpack = require('webpack'); 
const ExtractTextPlugin = require("extract-text-webpack-plugin"); 
const context = path.resolve('.'); 


module.exports = { 
    context: context, 
    entry: './src/client.js', 
    output: { 
    path: path.join(context, 'build/client'), 
    publicPath: '/static/', 
    filename: '[name]-[hash].js' 
    }, 
    module: { 
    preLoaders: [ 
     { 
     test: /\.js$/, 
     exclude: /node_modules/, 
     loader: 'eslint-loader' 
     }, 
    ], 
    loaders: [{ 
     test: /(?:node_modules).+\.css$/, 
     loader: 'style!css' 
    }, { 
     test: /\.scss$/, 
     loader: ExtractTextPlugin.extract([ 
     'css-loader', 
     'postcss-loader', 
     'sass-loader', 
     'sass-resources' 
     ]) 
    }, { 
     test: /\.js$/, 
     loader: 'babel', 
     exclude: /(node_modules)/ 
    }, { 
    test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, 
    loader: "url?limit=10000&mimetype=application/font-woff" 
    }, { 
    test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, 
    loader: "url?limit=10000&mimetype=application/font-woff" 
    }, { 
    test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 
    loader: "url?limit=10000&mimetype=application/octet-stream" 
    }, { 
    test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 
    loader: "file" 
    }, { 
    test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 
    loader: "url?limit=10000&mimetype=image/svg+xml" 
    }, { 
     test: /\.json$/, 
     loader: 'json' 
    }] 
    }, 
    postcss: function() { 
    return [ 
     require('autoprefixer') 
    ]; 
    }, 
    sassResources: [ 
    path.resolve(__dirname, '../src/stylesheets/base/_variables.scss'), 
    path.resolve(__dirname, '../src/stylesheets/base/_mixins.scss') 
    ], 
    devServer: { 
    watchOptions: { 
     aggregateTimeout: 1000 
    } 
    }, 
    plugins: [ 
    new ExtractTextPlugin("[name]-[hash].css"), 
    new webpack.DefinePlugin({ 
     'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'local') 
    }) 
    ], 
    devtool: "cheap-module-source-map" 
}; 

我有顯示瀏覽器的控制檯上errors沒有問題,但有沒有辦法只抑制瀏覽器的控制檯,而不是警告節點終端?

回答

2

https://devhub.io/repos/coryhouse-eslint-loader

在我webpack.config.js我有選擇的設置:

module: { 
    rules: [ 
    { 
     test: /\.js$/, 
     exclude: /(node_modules)/, 
     use: [ 
     { 
      loader: 'babel-loader', 
      options: { 
      presets: [ 
       ['es2015', {modules: false}], 
       'react' 
      ], 
      plugins: [ 'react-hot-loader/babel' ] 
      } 
     }, { 
      loader: 'eslint-loader', 
      options: { 
      quiet: true 
      } 
     } 
     ] 
    } 
    ] 
} 

的最後一行是quiet: true,這是如何抑制警告。

+1

這也隱藏了節點終端上的警告,而不僅僅是在瀏覽器控制檯上 – Mel

+1

是的,我正在尋找一種方法在終端中有日誌,但不在瀏覽器中。 –