2017-02-14 20 views
10

我試圖添加查詢的.png/.ttf加載爲webpack,否則在編譯時給我提供關於棄用的警告,升級到webpack 2後。Webpack 2:錯誤:選項/查詢不能用於加載程序(使用每個數組項目的選項)

這是我的配置。如何正確添加查詢的照片和字體?

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', 
        }, 
       ], 
       query: { 
        gifsicle: { 
         interlaced: false, 
        }, 
        optipng: { 
         optimizationLevel: 4, 
        }, 
        pngquant: { 
         quality: '75-90', 
         speed: 3, 
        }, 
       } 

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

回答

-3

刪除'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false',突然使所有的警告消失。所以我想,解決它 - 儘管我不知道爲什麼,這是不好的:-)

+1

如果問題與image-webpack-loader – chetan92

24

我在的WebPack配置

{ test: /\.(ts|tsx)$/, 
    loader: ['ts-loader'], 
    options: { appendTsSuffixTo: [/\.vue$/] } }, 

過這個片段當我刪除了[]圍繞「TS 「加載器」的錯誤消失了,例如

{ test: /\.(ts|tsx)$/, 
    loader: 'ts-loader', 
    options: { appendTsSuffixTo: [/\.vue$/] } }, 

我認爲該消息是說你不能使用選項/查詢多個裝載機。它不能是一個數組,它必須是一個單一的加載器。

+2

'/ \。(ts | tsx)$ /'可以是'/ \。tsx?$ /' – Sam

+0

@Sam有關,對,謝謝。 – reggaeguitar

+0

爲什麼downvote? – reggaeguitar

相關問題