抑制Webpack 2 + ESLint额外输出(堆栈跟踪)

时间:2017-04-14 00:26:29

标签: webpack webpack-dev-server eslint webpack-2

我正在将项目从create-react-app迁移到自定义Webpack 2配置,到目前为止,除了ESLint输出之外,我所有工作都在CRA版本中工作。

我以前见过以下......

预期产出:

WARNING in ./src/apps/NotesApp/components/Replies/ReplyEditor.js

./src/apps/NotesApp/components/Replies/ReplyEditor.js
  17:1  warning  Line 17 exceeds the maximum line length of 120  max-len

✖ 1 problem (0 errors, 1 warning)

但是现在我得到一个完整的堆栈跟踪,使这些警告占用控制台/终端空间的2-3倍。

邪恶的输出:

WARNING in ./src/apps/NotesApp/components/Replies/ReplyEditor.js

./src/apps/NotesApp/components/Replies/ReplyEditor.js
  17:1  warning  Line 17 exceeds the maximum line length of 120  max-len

✖ 1 problem (0 errors, 1 warning)

 @ ./src/apps/NotesApp/components/Replies/Replies.js 3:0-40
 @ ./src/apps/NotesApp/components/Replies/ReplyPanel.js
 @ ./src/apps/NotesApp/components/Note.js
 @ ./src/apps/NotesApp/components/NotesList.js
 @ ./src/apps/NotesApp/containers/NotesModal.js
 @ ./src/apps/NotesApp/components/NotesApp.js
 @ ./src/apps/NotesApp/index.js
 @ ./build/buildImport.js
 @ ./src/apps/AppsLibrary/LibraryRoutes.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server (webpack)-dev-server/client?/ (webpack)/hot/dev-server.js react-hot-loader/patch ./src/index

我尝试过的......

以下webpack.config.js选项完全摆脱了所有输出(我不想要):

  1. devServer: { stats: 'none' }
  2. devServer: { quiet: true }
  3. devServer: { stats: { warnings: false }}
  4. devServer.stats的每个其他选项都对堆栈跟踪没有影响。

    只是为了看看ESLint是否正在创建堆栈跟踪,我将自定义格式化程序设置为返回空白:

    rules: [
      {
        enforce: 'pre',
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: { formatter: message => '' }
      }
    ]
    

    ...具有以下输出:

    WARNING in ./src/apps/NotesApp/components/Replies/ReplyEditor.js
    ESLintError
     @ ./src/apps/NotesApp/components/Replies/Replies.js 3:0-40
     @ ./src/apps/NotesApp/components/Replies/ReplyPanel.js
     @ ./src/apps/NotesApp/components/Note.js
     @ ./src/apps/NotesApp/components/NotesList.js
     @ ./src/apps/NotesApp/containers/NotesModal.js
     @ ./src/apps/NotesApp/components/NotesApp.js
     @ ./src/apps/NotesApp/index.js
     @ ./build/buildImport.js
     @ ./src/apps/AppsLibrary/LibraryRoutes.js
     @ ./src/index.js
     @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server (webpack)-dev-server/client?/ (webpack)/hot/dev-server.js react-hot-loader/patch ./src/index
    

    webpackDevServer的node.js执行创建了一个stats对象,其中包含有关devServer的所有错误,警告和其他信息,每个stats.warnings都是一个格式化为shell的消息,如下所示:

    "./src/apps/NotesApp/components/Replies/ReplyEditor.js
    
    [4m./src/apps/NotesApp/components/Replies/ReplyEditor.js[24m
      [2m17:1[22m  [33mwarning[39m  Line 17 exceeds the maximum line length of 120  [2mmax-len[22m
    
    [33m[1m✖ 1 problem (0 errors, 1 warning)
    [22m[39m
     @ ./src/apps/NotesApp/components/Replies/Replies.js 3:0-40
     @ ./src/apps/NotesApp/components/Replies/ReplyPanel.js
     @ ./src/apps/NotesApp/components/Note.js
     @ ./src/apps/NotesApp/components/NotesList.js
     @ ./src/apps/NotesApp/containers/NotesModal.js
     @ ./src/apps/NotesApp/components/NotesApp.js
     @ ./src/apps/NotesApp/index.js
     @ ./build/buildImport.js
     @ ./src/apps/AppsLibrary/LibraryRoutes.js
     @ ./src/index.js
     @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server (webpack)-dev-server/client?/ (webpack)/hot/dev-server.js react-hot-loader/patch ./src/index"
    

    ...这看起来像我可以拦截消息并执行stats.warnings.map(message => message.replace(/^\s*(at|@)+.*\n*/gm, ''))之类的操作,但这也没有效果。

    有没有人知道这个堆栈跟踪的生成位置以及是否有任何方法可以将其关闭?

0 个答案:

没有答案