使用url-loader报错Source code omitted for this binary file

来源:3-7 webpack对icon-font和图片的处理

慕粉3521182

2017-09-18

webpack.config.js

/*
* @Author: wqy
* @Date:   2017-07-22 22:53:17
* @Last Modified by:   wqy
* @Last Modified time: 2017-09-18 22:31:49
*/
 var webpack = require('webpack');
 var ExtractTextPlugin = require("extract-text-webpack-plugin");
 var HtmlWebpackPlugin = require('html-webpack-plugin');
 var path = require("path");
 var getHtmlConfig = function(name){
    return{
            template : './src/view/'+name+'.html',
            filename : 'view/'+name+'.html',
            inject : true,
            hash : true,
            chunks : ['common',name]
        }
 }
var config = {
     entry: {
        'common' : ['./src/page/commons/index.js'],
         'index' : ['./src/page/index/index.js'],
         'login' : ['./src/page/login/index.js']
     },
     output: {
         path: path.resolve(__dirname, './dist'),
         filename: 'js/[name].js'
     },
     externals : {
         'jquery' : 'window.jQuery'
     },
      module: {
        rules: [
           {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                  fallback: 'style-loader',
                  //resolve-url-loader may be chained before sass-loader if necessary
                  use: ['css-loader', 'sass-loader']
                })
            }
        ],
        loaders: [
            {
                test: /\.(svg|gif|png|eot|woff|ttf|jpg)$/,
      loader: 'url-loader'
            }
        ]
      },
     plugins : [
       //
        new webpack.optimize.CommonsChunkPlugin({
            name : 'common',
            filename : 'js/base.js'
        }),
        new ExtractTextPlugin("css/[name].css"),
        new HtmlWebpackPlugin(getHtmlConfig('index')),
        new HtmlWebpackPlugin(getHtmlConfig('login')),
     ]
 }
 module.exports = config

执行webpack错误如下:

    ERROR in ./src/image/timg.jpg
    Module parse failed: /Users/wqy/Documents/workspace/mmall/mmall-fe/src/image/timg.jpg Unexpected character '�' (1:0)
    You may need an appropriate loader to handle this file type.
    (Source code omitted for this binary file)
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/page/index/index.scss 6:184-215

写回答

1回答

Rosen

2017-09-19

安装file-loader 然后给url-loader加上?limit=100&name=resource/[name].[ext] 试试

0
1
慕粉3521182
非常感谢!可以了
2017-09-19
共1条回复

真实数据对接 从0开发前后端分离的企业级上线项目

【毕设项目精品】前端实战,对接真实服务端数据,开发完整项目

4262 学习 · 4113 问题

查看课程