Webpack 2:.png、.svg、.. 中的警告已弃用。在它自己的选项中配置 optipng 的 optimizationLevel 选项。 (optipng.optimizationLevel)
Webpack 2: WARNING in .png, .svg, .. DEPRECATED. Configure optipng's optimizationLevel option in it's own options. (optipng.optimizationLevel)
此警告在 运行 webpack
时打印了约 20 次 - 它可以很好地处理和捆绑,但这是什么意思?我该如何摆脱它?
不幸的是,谷歌搜索几乎没有帮助。
这是我的 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]'
}
]
},
};
警告示例(有很多!)
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
您现在需要为特定的优化器指定您的选项。所以以前的 webpack 1.x 加载器配置像;
loaders: [
'file-loader?name=assets/[name].[ext]',
'image-webpack-loader?progressive=true&optimizationLevel=7&interlaced=true'
]
变成
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,
}
}
}
}]
注意选项对象,其中嵌入了查询。
见
https://webpack.js.org/guides/migrating/
和
deltones 在这个问题上的评论;
https://github.com/tcoopman/image-webpack-loader/issues/68#issuecomment-275848595
Webpack 2 现在支持 "query object" 语法,这意味着您可以为查询参数创建一个单独的对象。以下是 image-webpack-loader
在 their documentation 中的推荐方式。我用最新的 webpack 2 命名标准更新了它:
rules: [ // rules is formerly "loaders" in webpack 1
{
test: /\.(svg|jpe?g|png|gif|ico)(\?{0}(?=\?|$))/,
use: [ // use is formerly "loaders" in webpack 1
// file-loader has a bug where it doesn't yet recognize query object
// syntax for webpack 2, so the query options `assets/images/[name].[ext]`
// are ignored until they fix that,
// {
// loader: 'file',
// query: {
// name: 'assets/images/[name].[ext]'
// }
//},
'file?name=assets/images/[name].[ext]', // or just 'file-loader'
{
loader: 'image-webpack',
query: {
progressive: true,
optimizationLevel: 7,
interlaced: false,
pngquant: {
quality: '65-90',
speed: 4
}
}
// you can also do it like this:
// query: {
// mozjpeg: {
// progressive: true,
// },
// gifsicle: {
// interlaced: false,
// },
// optipng: {
// optimizationLevel: 7,
// }
// }
}
]
}
]
注意 rules
与 webpack 1 顶层 loaders
相同, use
与 webpack 1 loaders
在单独加载器级别相同( test
之后的一个)。如您所见,之前很混乱,这就是为什么 schema 在 webpack 2 中被重命名的原因。
None 以上对我有用,从官方 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
}
}
}
]
}
image-webpack-loader 的以下 webpack2 配置对我来说工作正常:
{
loader: 'image-webpack-loader',
options: {
progressive: true,
optipng: {
optimizationLevel: 7,
},
mozjpeg: {
quality: 65
},
gifsicle: {
interlaced: true,
},
pngquant: {
quality: '65-90',
speed: 4
}
}
}
这是由于查询对象中的参数现在属于其中一个子对象。
例如:
这很糟糕:
'file-loader',
{
loader: 'image-webpack-loader',
query: {
progressive: true,
optimizationLevel: 7,
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
}
}
}
哪里好:
'file-loader',
{
loader: 'image-webpack-loader',
query: {
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
}
}
}
此警告在 运行 webpack
时打印了约 20 次 - 它可以很好地处理和捆绑,但这是什么意思?我该如何摆脱它?
不幸的是,谷歌搜索几乎没有帮助。
这是我的 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]'
}
]
},
};
警告示例(有很多!)
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
您现在需要为特定的优化器指定您的选项。所以以前的 webpack 1.x 加载器配置像;
loaders: [
'file-loader?name=assets/[name].[ext]',
'image-webpack-loader?progressive=true&optimizationLevel=7&interlaced=true'
]
变成
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,
}
}
}
}]
注意选项对象,其中嵌入了查询。
见 https://webpack.js.org/guides/migrating/ 和 deltones 在这个问题上的评论; https://github.com/tcoopman/image-webpack-loader/issues/68#issuecomment-275848595
Webpack 2 现在支持 "query object" 语法,这意味着您可以为查询参数创建一个单独的对象。以下是 image-webpack-loader
在 their documentation 中的推荐方式。我用最新的 webpack 2 命名标准更新了它:
rules: [ // rules is formerly "loaders" in webpack 1
{
test: /\.(svg|jpe?g|png|gif|ico)(\?{0}(?=\?|$))/,
use: [ // use is formerly "loaders" in webpack 1
// file-loader has a bug where it doesn't yet recognize query object
// syntax for webpack 2, so the query options `assets/images/[name].[ext]`
// are ignored until they fix that,
// {
// loader: 'file',
// query: {
// name: 'assets/images/[name].[ext]'
// }
//},
'file?name=assets/images/[name].[ext]', // or just 'file-loader'
{
loader: 'image-webpack',
query: {
progressive: true,
optimizationLevel: 7,
interlaced: false,
pngquant: {
quality: '65-90',
speed: 4
}
}
// you can also do it like this:
// query: {
// mozjpeg: {
// progressive: true,
// },
// gifsicle: {
// interlaced: false,
// },
// optipng: {
// optimizationLevel: 7,
// }
// }
}
]
}
]
注意 rules
与 webpack 1 顶层 loaders
相同, use
与 webpack 1 loaders
在单独加载器级别相同( test
之后的一个)。如您所见,之前很混乱,这就是为什么 schema 在 webpack 2 中被重命名的原因。
None 以上对我有用,从官方 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
}
}
}
]
}
image-webpack-loader 的以下 webpack2 配置对我来说工作正常:
{
loader: 'image-webpack-loader',
options: {
progressive: true,
optipng: {
optimizationLevel: 7,
},
mozjpeg: {
quality: 65
},
gifsicle: {
interlaced: true,
},
pngquant: {
quality: '65-90',
speed: 4
}
}
}
这是由于查询对象中的参数现在属于其中一个子对象。
例如:
这很糟糕:
'file-loader',
{
loader: 'image-webpack-loader',
query: {
progressive: true,
optimizationLevel: 7,
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
}
}
}
哪里好:
'file-loader',
{
loader: 'image-webpack-loader',
query: {
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
}
}
}