Webpack 2:警告.png,.svg,..已弃用.在它自己的选项中配置optipng的optimizationLevel选项.(optipng.optimizationLevel)

cbl*_*bll 9 javascript svg webpack webpack-style-loader webpack-2

这个警告在运行时被打印~20次webpack- 它处理和捆绑很好,但它是什么意思?我怎么摆脱它?

谷歌周围提供很少甚至没有帮助.

这是我的webpack配置:

const ExtractTextPlugin = require("extract-text-webpack-plugin");

var webpack = require("webpack");

module.exports = {
    entry: {
        dashboard: './js/main.js',
        vendor: ["fixed-data-table","react","react-dom","jquery", "bootstrap", "vis",],
    },
    output: { path: "../public", filename: 'bundle.js' },

    plugins: [
        new webpack.optimize.CommonsChunkPlugin({name: "vendor", filename: "static/vendor.bundle.js"}),
        new ExtractTextPlugin("/static/[name].css"),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        }),
    ],

    module: {
        loaders: [
            {
                test: /.js?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: [
                        'es2015', 'react', 'stage-0',
                    ],

            }
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader'}),
            },
            {
                test: /\.(jpe?g|png|gif|svg)$/i,
                loaders: [
                    'file-loader?hash=sha512&digest=hex&name=~/.local/share/Trash/[hash].[ext]',
                    'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false', {
                        loader: 'image-webpack-loader',
                    }
                ],

            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file-loader?name=~/.local/share/Trash/[name].[ext]'
            }
        ]
    },
};
Run Code Online (Sandbox Code Playgroud)

警告样本(有很多!)

WARNING in ./~/vis/dist/img/network/addNodeIcon.png
DEPRECATED. Configure gifsicle's interlaced option in it's own options. (gifsicle.interlaced)
 @ ./~/css-loader!./~/vis/dist/vis.min.css 6:12847-12887
 @ ./~/vis/dist/vis.min.css

WARNING in ./~/bootstrap/dist/fonts/glyphicons-halflings-regular.svg
DEPRECATED. Configure gifsicle's interlaced option in it's own options. (gifsicle.interlaced)
 @ ./~/css-loader!./~/bootstrap/dist/css/bootstrap.min.css 6:3700-3752
 @ ./~/bootstrap/dist/css/bootstrap.min.css
Run Code Online (Sandbox Code Playgroud)

小智 27

您现在需要为特定优化器指定选项.所以以前的webpack 1.x loader配置像;

loaders: [
  'file-loader?name=assets/[name].[ext]',
  'image-webpack-loader?progressive=true&optimizationLevel=7&interlaced=true'
]
Run Code Online (Sandbox Code Playgroud)

      use: [
    {
      loader: 'file-loader',
      options: {
        query: {
          name:'assets/[name].[ext]'
        }
      }
    },
    {
      loader: 'image-webpack-loader',
      options: {
        query: {
          mozjpeg: {
            progressive: true,
          },
          gifsicle: {
            interlaced: true,
          },
          optipng: {
            optimizationLevel: 7,
          }
        }
      }
    }]
Run Code Online (Sandbox Code Playgroud)

注意options对象,其中嵌入了查询.

请参阅 此问题中的https://webpack.js.org/guides/migrating/和deltones评论; https://github.com/tcoopman/image-webpack-loader/issues/68#issuecomment-275848595


cra*_*ash 10

以上都不适用于我,从官方webpack2配置示例中获取灵感https://github.com/tcoopman/image-webpack-loader/blob/master/test/webpack2.config.js这对我有用

  {
    test: /\.(png|jpe?g|gif|svg)$/,
    use: [
      {
        loader: 'file-loader',
        options: {
          // path where the images will be saved
          name: 'assets/img/[name].[ext]'
        }
      },
      {
        loader: 'image-webpack-loader',
        options: {
          mozjpeg: {
            quality: 65
          },
          pngquant:{
            quality: "10-20",
            speed: 4
          },
          svgo:{
            plugins: [
              {
                removeViewBox: false
              },
              {
                removeEmptyAttrs: false
              }
            ]
          },
          gifsicle: {
            optimizationLevel: 7,
            interlaced: false
          },
          optipng: {
            optimizationLevel: 7,
            interlaced: false
          }
        }
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)