5. 이미지 파일 모듈로 다루어보기(file-loader)
npm i file-loader -Dmodule.exports = { module: { rules: [ { //svg확장자는 url-loader에서 다룰 예정 //i의의미: 대소문자 구분 X test: /\.(png|jpe?g|gif)$/i, use: [ { loader: 'file-loader', options: { // ext: 확장자 약어 name: '[contenthash].[ext]', }, }, ], }, ], }, };import cuteImg from './images/cute.png'; const imgElement = document.createElement('img'); imgElement.src = cuteImg;
module.exports = { entry: './src/index.js', };
publicPath: 'assets/', outputPath: 'assets/'
module.exports = { module: { rules: [ { test: /\.(png|jpe?g|gif)$/i, loader: 'file-loader', options: { name() { if (!isProduction) { return '[path][name].[ext]'; } return '[contenthash].[ext]'; }, }, }, ], }, };
Last updated