Assets dalam JavaScript Bundles di Webpack
Mari kita konfigurasi assets untuk file
.png:
export default {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve('dist')
},
module: {
rules: [
{
test: /\.png$/,
type: 'asset/resource'
}
]
},
plugins: [
new HtmlWebpackPlugin(),
],
};
Mari impor file .png ke entry point:
import img from './images/main.png';
Variabel img akan berisi
path baru ke file gambar:
console.log(img);
Konfigurasikan assets untuk file
.jpg.
Impor beberapa gambar ke entry point.
Tampilkan path baru ke gambar di file entry point.