I am trying to get Webpack 4 to output a .png file into /dist/assets, and have that be used by my index.html file via file-loader.
The .png file does output into dist/assets, but it does not get loaded in by the browser. Funny thing, I treat my .png files the same as my font files in my webpack.config.js, and the font files are loaded in by the browser.
Below is my file directory when building
Below is code from webpack.config.js that I believe to be pertinent to this issue.
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
...
{
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './assets'
}
},
...
The whole webpack.config.js is below, or can be found (along with the other files) at the repository in which this code is hosted at.
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
/*publicPath: 'dist'*/
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
},
{
test: /\.vue$/,
//exclude: /node_modules/,
loader: 'vue-loader',
},
{
test: /\.(sa|sc)ss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader' // Loads a sass / scss file and compiles it to CSS
]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './assets'
}
},
{
test: /\.svg$/,
use: [
'vue-svg-icon-loader'
],
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: 'bundle.css',
chunckFilename: '[id].css',
})
]
}