代码之家  ›  专栏  ›  技术社区  ›  Elvira

可能只在网页包中显示错误?

  •  1
  • Elvira  · 技术社区  · 7 年前

    当我的文件发生变化时,webpack watch会显示大量文本(是下图的3倍)。这让我抓狂,因为我只想看到已更改的文件或可能发生的错误。我对错误视而不见,因为文本太多了。

    是否可以只显示错误,或只显示实际更改的文件?如果是的话,我怎样才能做到这一点呢?

    enter image description here

    这是我的配置:

    // webpack.config.js
    const webpack = require("webpack");
    const path = require("path");
    const CopyWebpackPlugin = require("copy-webpack-plugin");
    const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    
    const config = {
      context: path.resolve(__dirname),
      entry: "./index.js",
      devServer: {
        contentBase: "./dist",
        stats: { chunks: false } 
      },
      output: {
        path: path.resolve(__dirname, "dist"),
        filename: "bundle.js"
      },
      resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".ts", ".tsx", ".js", ".json"]
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            include: path.resolve(__dirname),
            use: [
              {
                loader: "babel-loader",
                options: {
                  presets: [["@babel/env", { modules: false }], "@babel/react"]
                }
              }
            ]
          },
          {
            test: /\.tsx?$/,
            loader: "awesome-typescript-loader"
          },
          {
             test: /\.css$/,
             use: [MiniCssExtractPlugin.loader, "css-loader"]
           }
        ],
        noParse: [/aws-sdk/]
      },
      plugins: [
        new webpack.DefinePlugin({
          "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
          "process.env.STATIC_PORT": JSON.stringify(process.env.STATIC_PORT),
          VERSION: JSON.stringify(require("./package.json").version)
        }),
        new MiniCssExtractPlugin({
          filename: 'bundle.css'
        }),
        new CopyWebpackPlugin([{ from: "./cb_icons", to: "cb_icons" }])
      ],
      node: { fs: "empty" },
      externals: [{ "./cptable": "var cptable" }, { "./jszip": "jszip" }],
      performance: { hints: false },
      watchOptions: {
       ignored: ['node_modules'],
       poll: 1000
     }
    };
    
    module.exports = config;
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   funnydman    7 年前

    是的,可以通过 stats 选项,根据文档:

    https://webpack.js.org/configuration/dev-server/#devserver-stats-

    如果只想记录错误消息:

    devServer: {
        stats: 'errors-only'
      }
    

    另外,看看这个选项:

    https://webpack.js.org/configuration/dev-server/#devserver-clientloglevel

    推荐文章