首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mini-css-extract-plugin产生的大量控制台输出

mini-css-extract-plugin产生的大量控制台输出
EN

Stack Overflow用户
提问于 2019-06-21 19:59:06
回答 2查看 2.5K关注 0票数 9

我一直在尝试研究这一点,但似乎没有其他任何人有这一点,或者认为这是一个问题。

我在我的webpack.config.js中使用mini-css-extract-plugin(MiniCssExtractPlugin)。

然而,当我运行webpack时,控制台上到处都是类似于以下内容的成百上千个实例...

代码语言:javascript
复制
Child mini-css-extract-plugin ../../../node_modules/css-loader/index.js??ref--6-1!../../../node_modules/postcss-loader/src/index.js!../../../node_modules/sass-loader/lib/loader.js!ui/radiolist-toggler/RadioListToggler.scss:
    Entrypoint mini-css-extract-plugin = *
    [../../../node_modules/css-loader/index.js?!../../../node_modules/postcss-loader/src/index.js!../../../node_modules/sass-loader/lib/loader.js!./ui/radiolist-toggler/RadioListToggler.scss] /Users/~~~/git/user-section/node_modules/css-loader??ref--6-1!/Users/~~~/git/user-section/node_modules/postcss-loader/src!/Users/~~/git/user-section/node_modules/sass-loader/lib/loader.js!./ui/radiolist-toggler/RadioListToggler.scss 5.33 KiB {mini-css-extract-plugin} [built]
        + 1 hidden module

我需要滚动几秒钟才能看到我所有的资产等。

我还是个新手,所以不太确定如何防止这段代码输出到控制台?

下面是我的webpack.config.js

代码语言:javascript
复制
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const modernizr = require("modernizr");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');


module.exports = {
  context: path.resolve(__dirname, 'src/main/client'),
  entry: './index',
  devtool: 'cheap-module-source-map',
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        cache: true,
        parallel: true,
        uglifyOptions: {
          mangle: true,
          compress: true,
          ecma: 6
        },
        sourceMap: true
      }),
      new OptimizeCssAssetsPlugin({}),
    ],
    splitChunks: {
      chunks: 'all'
    }
  },
  plugins: [
    new CompressionPlugin({
      test: /\.js$|\.css$|\.html$|\.(png|svg|jpg|gif)$/,
      cache: true,
      filename: '[path].gz[query]',
      algorithm: 'gzip',
      threshold: 10240
    }),
    new CleanWebpackPlugin([
      './target/webapp'
    ]),
    new HtmlWebpackPlugin({
      template: './index.html',
      filename: '../index.html',
      xhtml: true
    }),
    new MiniCssExtractPlugin({
      filename: "[name].css",
    }),
    new CopyWebpackPlugin([{
      from: '../webapp/**/*',
      to: '../'
    }]),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"'
    }),
  ],
  output: {
    publicPath: '/app/',
    filename: '[name].bundle.js',
    chunkFilename: '[id].js',
    path: path.resolve(__dirname, 'target/webapp/app/')
  },
  module: {
    rules: [{
        loader: "webpack-modernizr-loader",
        test: /\.modernizrrc\.js$/
      },
      {
        test: /\.html$/,
        exclude: /node_modules/,
        use: {
          loader: 'html-loader'
        }
      },
      {
        test: /\.s?css$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1
            }
          },
          {
            loader: 'postcss-loader'
          },
          {
            loader: 'sass-loader'
          }
        ]
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: [
          'file-loader'
        ]
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: [{
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: './assets/fonts/'
          }
        }]
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: "babel-loader",
        options: {
          presets: ["@babel/env"]
        }
      }
    ],
  },
  resolve: {
    alias: {
      // You can add comment "Please do not delete this file" in this file
      modernizr$: path.resolve(__dirname, "./.modernizrrc.js")
    }
  }
}
EN

回答 2

Stack Overflow用户

发布于 2020-06-01 06:43:42

@mcclosa提到这是一个注释,但如果有人看到这个问题,没有看到答案并单击离开,解决方案是将stats选项添加到您的webpack.config.js文件中,如下所示:

代码语言:javascript
复制
module.exports = {
   stats: { children: false },
}

上面的选项使用了@mcclosa建议的children: false选项,它确实成功地删除了mini-css- stats: "minimal" -plugin的垃圾输出,但我发现使用预设的plugin会产生更好的整体输出。使用:

代码语言:javascript
复制
module.exports = {
   stats: "minimal",
}

只要我的构建没有错误,就给我..gives下面的小输出:

代码语言:javascript
复制
i 「wdm」: Compiling...
i 「wdm」:    69 modules
i 「wdm」: Compiled successfully.

..as反对几十行无用的构建数据,但当出现错误时,它将继续给出错误信息。

票数 12
EN

Stack Overflow用户

发布于 2021-04-01 20:31:41

不幸的是,mini-css-extract-loader没有设置来控制其日志输出的详细程度。

webpack.config.js中将stats.children设置为false"minimal"可能会删除许多其他有用的输出,如包的名称和大小、入口点信息、构建所需的时间、合法的警告以及您可能希望保留的其他插件的错误等。

相反,我们似乎必须添加一个在编译器的提取钩子上执行的插件,以便从与mini-css- done - plugin关联的stats.compilation对象中删除项。

这个示例插件应该可以工作:

代码语言:javascript
复制
class CleanupMiniCssExtractPlugin {
  apply(compiler) {
    compiler.hooks.done.tap("CleanupMiniCssExtractPlugin", stats => {
      if (this._children) {
        const children = stats.compilation.children;
        if (Array.isArray(children)) {
          stats.compilation.children = children.filter(
            child => child.name.indexOf("mini-css-extract-plugin") == -1
          );
        }
      }
    });
  }
}

或者您可以使用这个npm包:https://www.npmjs.com/package/cleanup-mini-css-extract-plugin

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56703039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档