In my vue(2.0)+ webpack project, I config vue-html-loader, but in my .vue files img tag cannot load static src images. Below is my webpack config:
module: {
loaders: [
...
{
test: /\.html$/,
exclude: /node_modules/,
loaders: ['html', 'html-minify']
}
, {
test: /\.vue$/,
loader: 'vue'
}
...
]
},
vue: {
...
html: {
root: path.resolve(__dirname, './source/static'),
attrs: ['img:src', 'img:srcset']
},
loaders: {
css: ExtractTextPlugin.extract("css"),
sass: ExtractTextPlugin.extract("css!sass")
}
},
resolve: {
root: [
path.resolve('./source')
],
extensions: ['', '.js', '.json', '.scss', '.html', '.css', '.vue'],
alias: {
'vue': 'vue/dist/vue.js'
}
},
Below is my .vue file:
<img src="/web/img/[email protected]" srcset="/web/img/[email protected]" />
My browser always come out 404 error. Did somebody get the same problem?
url-loader
for static images. I highly recommend the webpack template used byvue-cli
. See github.com/vuejs-templates/webpack/blob/master/template/build/… – Phil