14 webpack using the url-loader

By default, webpack can not handle css file url address, whether it is pictures or font library, as long as the URL address, you can not handle, you need a third-party loader
1. Installation loader

cnpm i url-loader file-loader -D   //file-loader是url-loader的内部依赖,在配置文件中不必配置file-loader

2. Profiles webpack.config.js new third-party matching rules

module:{//配置所有第三方loader模块的
    rules:[//第三方模块的匹配规则
    {test:/\.(jpg|png|gif|bmp|jpeg)$/,use:'url-loader?limit=7632&name=[hash:8]-[name].[ext]'},//处理图片路径的loader
    //limit给定的值,是图片的大小,单位是byte,如果我们音乐的图片,大于或等于给定的limit值,
    则不会被转为base64格式的字符串,如果图片小于给定的limit值,则会被转为base64的字符串   
    //name=[name].[ext]:name属性指向原来的名称,例test.jpg
    //[hash:8]:取前8位hash值
    ]
}

Guess you like

Origin www.cnblogs.com/songsongblue/p/11876991.html