Assets trong JavaScript Bundles tại Webpack
Hãy cấu hình assets cho các 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(),
],
};
Hãy kết nối file .png tới entry point:
import img from './images/main.png';
Vào biến img sẽ nhận được
đường dẫn mới tới file ảnh:
console.log(img);
Hãy cấu hình assets cho các file
.jpg.
Hãy kết nối nhiều ảnh tới entry point.
Hãy xuất ra các đường dẫn mới tới ảnh trong file entry point.