Javascript 网页包忽略统计信息选项

Javascript 网页包忽略统计信息选项,javascript,node.js,reactjs,webpack,Javascript,Node.js,Reactjs,Webpack,更新 @Daniel Khoroshko的回答解决了我的统计问题。作为将来的参考,webpack有(至少)4种处理统计数据的方法: 将stats视为常规网页选项 如果使用devServer,则必须将其放置在该对象中(请参见上面链接中的注释) 如果使用节点API,则它必须位于回调函数中 正如Daniel指出的,Webpackdev中间件覆盖stats,因此对象必须在那里 ================================================ 使用Webpack3.10,我

更新

@Daniel Khoroshko的回答解决了我的统计问题。作为将来的参考,webpack有(至少)4种处理统计数据的方法:

  • stats
    视为常规网页选项
  • 如果使用
    devServer
    ,则必须将其放置在该对象中(请参见上面链接中的注释)
  • 如果使用节点API,则它必须位于回调函数中
  • 正如Daniel指出的,
    Webpackdev中间件
    覆盖stats,因此对象必须在那里
  • ================================================

    使用Webpack3.10,我试图抑制百万
    提取文本webpack插件
    日志

    我们正在使用webpack节点API。在我们的
    server.js
    节点入口点中,我们有:

    // server.js
    
    const app = express();
    
    if (environment.isLocal) {
      require('./webpackConfig')(app);
    } else {
      app.use(compression());
    }
    // other stuff
    
    我们使用带有节点的网页包的地方:

    // webpackConfig.js
    
    const webpack = require('webpack');
    const config = require('../webpack.config.dev');
    
    module.exports = (app) => {
      const compiler = webpack(config, (err, stats) => {
        stats.toJson("none"); // none for brevity, but not working
      });
    
      app.use(require('webpack-dev-middleware')(compiler, {
        noInfo: true,
        publicPath: config.output.publicPath
      }));
    
      app.use(require('webpack-hot-middleware')(compiler));
    };
    
    最后,整个配置

    // webpack.config.dev.js
    
    module.exports = {
      devtool: 'cheap-module-source-map',
      entry: {
        app: [
          'eventsource-polyfill',
          'webpack-hot-middleware/client?reload=true',
          './src/index'
        ]
      },
      target: 'web',
      output: {
        path: __dirname + '/dist',
        publicPath: '/',
        filename: '[name].js'
      },
      devServer: {
        contentBase: './src'
      },
      plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new ExtractTextPlugin('[name]-[hash].css'),
        new HtmlWebpackPlugin({
          title: 'annoying webpack', 
          template: './src/index.html', 
          alwaysWriteToDisk: true,
          inject: false
        }),
        new HtmlWebpackHarddiskPlugin()
      ],
      module: {
        rules: [
          {
            test: /\.js$/,
            enforce: 'pre',
            loader: require.resolve('eslint-loader'),
            options: {
              failOnWarning: false,
              failOnError: false
            },
            exclude: /node_modules|dist/
          },
          {
            test: /\.js$/,
            include: [path.join(__dirname, 'src')]
            loader: 'babel-loader'
          }
        ]
      }
    };
    
    控制台中的输出

    webpack building...
    webpack built c22fd3ae797ecd55eccc in 7410ms
    ℹ 「wdm」: Hash: c22fd3ae797ecd55eccc
    Version: webpack 3.10.0
    Time: 7410ms
                           Asset       Size  Chunks                    
    Chunk Names
                          app.js    2.53 MB       0  [emitted]  [big]  
    app
    app-c22fd3ae797ecd55eccc.css     125 kB       0  [emitted]         
    app
                      app.js.map    2.97 MB       0  [emitted]         
    app
    app-c22fd3ae797ecd55eccc.css.map    4.71 kB       0  [emitted]         
    app
                      index.html  275 bytes          [emitted]
       [3] ./node_modules/react/react.js 56 bytes {0} {0} [built]
     [100] ./node_modules/react-dom/index.js 59 bytes {0} {0} [built]
     [107] ./node_modules/react-redux/es/index.js 230 bytes {0} {0} 
    [built]
       ..... 
        + 867 hidden modules
        Child html-webpack-plugin for "index.html":
             Asset    Size  Chunks  Chunk Names
        index.html  568 kB       0
        .....   
    ℹ 「wdm」: Compiled successfully.
    webpack built d7509fff9f1c995bf5ee in 7523ms
    ℹ 「wdm」: Hash: d7509fff9f1c995bf5ee
    Version: webpack 3.10.0
    Time: 7523ms
                           Asset       Size  Chunks                    
    Chunk Names
                          app.js    2.53 MB       0  [emitted]  [big]  
    app
    app-d7509fff9f1c995bf5ee.css     125 kB       0  [emitted]         
    app
                      app.js.map    2.97 MB       0  [emitted]         
    app
    app-d7509fff9f1c995bf5ee.css.map    4.71 kB       0  [emitted]         
    app
                      index.html  275 bytes          [emitted]
       [5] ./src/App.js 3.62 kB [built]
       [6] ./src/store/configureStore.js 325 bytes [built]
       .....
        + 867 hidden modules
    Child html-webpack-plugin for "index.html":
         Asset    Size  Chunks  Chunk Names
    index.html  568 kB       0
       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 646 bytes {0} [built]
       [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [3] (webpack)/buildin/module.js 517 bytes {0} [built]
    ℹ 「wdm」: Compiled successfully.
    

    关于统计选项
    webpack-dev-middleware
    webpack-dev-server
    有自己的统计设置,我想这会覆盖webpack-own设置。我建议试试这个

      app.use(require('webpack-dev-middleware')(compiler, {
        noInfo: true,
        publicPath: config.output.publicPath,
        stats: 'errors-only'
      }));
    

    不幸的是,我不知道为什么它会构建两次:-(非常感谢您提供的统计修复!!!这很有效。我将编辑我的问题以突出显示该修复。嗨,我很高兴它可以工作。谈到双重构建-如果您要添加
    console.log('test'))
    导入您的网页配置文件后,它会打印两次吗?实际上我不确定我更改了什么,但它不再生成两次。我基本上是从以前的网页配置重新开始的,它一起出现了。再次感谢您的帮助