Skip to content

Commit

Permalink
file-loader image
Browse files Browse the repository at this point in the history
  • Loading branch information
swimly committed Mar 30, 2017
1 parent 2631ae5 commit 4af2ccd
Show file tree
Hide file tree
Showing 1,185 changed files with 91,323 additions and 8 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,33 @@ module.exports = {
```
最终效果如下:

<img src="book/13.gif"/>
<img src="book/13.gif"/>

#### 10、打包图片
```
npm i -D file-loader
```
```javascript
// add
{test: /\.jpg$/, use: 'file-loader'}
```
然后你就可以像往常一样随便的引入图片!
在html中要按如下使用:
```
<img src="<%= require('./img/bg.jpg')%>" alt="">
```
```
npm i -D image-webpack-loader
```
```
{
test: /\.(png|jpe?g|svg|gif|webp)$/,
use: [
'file-loader?name=images/[name].[ext]',
// 'file-loader?name=[hash:6].[ext]&publicPath=images/',
'image-webpack-loader?{optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}, mozjpeg: {quality: 65}}'
]
}
```
具体参考:[https://www.npmjs.com/package/image-webpack-loader](https://www.npmjs.com/package/image-webpack-loader)
2 changes: 1 addition & 1 deletion dist/app.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4af2ccd

Please sign in to comment.