鍍金池/ 問答/HTML5  HTML/ webpack打包圖片錯誤.

webpack打包圖片錯誤.

webpack.config.js


var webpack = require("webpack");
module.exports = {
    entry : {
        index : __dirname+"/src/index.js"
    },
    output : {
        path : __dirname+"/build",
        publicPath: '/assets/',
        filename : "bundle.js"
    },
    module : {
        loaders : [
            {
                test : /.vue$/,
                loader: 'vue-loader'
            },
            {
          test: /\.(png|jpg)$/,
          loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
        },
            {
          test: /\.html$/,
          loader: 'html-withimg-loader'
        }
        ]
    },
    resolve: {
        alias: {
            'vue': 'vue/dist/vue.js'
        }
    }
}

search.vue

<template>
    <div class="search">
        <h1><img src="assets/logo.jpg" /></h1>
    </div>
</template>
<script>
    
</script>

<style lang="scss">
    $nav-color: #F90;
    nav {
      background:url("assets/logo.jpg") no-repeat;
      $width: 100px;
      width: $width;
      color: $nav-color;
    }
</style>

圖片描述

回答
編輯回答
安于心

css 中使用的圖片資源,請放到static目錄下去,不要放在assert目錄

2017年2月25日 17:08
編輯回答
墨染殤

not found 沒有找到這個圖片資源,請確認(rèn)你的資源存在與否或者路徑是否正確。

2018年4月3日 01:19
編輯回答
伐木累

vue組件中的路徑仍應(yīng)是打包前的路徑,而不是打包后的路徑,webpack會幫你替換的

2017年8月19日 03:10
編輯回答
墨沫

打包路徑是放在images文件夾下的,需要加上images路徑

2017年6月11日 20:49