Closed sunmingtao closed 3 years ago
webpack.config.js
module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, './dist'), publicPath: 'dist/' }, ...
js
import Kiwi from './details.png'; function addImage() { const img = document.createElement('img'); img.width = 300; img.src = Kiwi; const body = document.querySelector('body'); body.appendChild(img); }
Inspect the html element
Now change it to publicPath: 'auto'
publicPath: 'auto'
It's also possible to change publicPath to a CDN URL. e.g. publicPath: 'https://some-cdn/'
publicPath: 'https://some-cdn/'
webpack.config.js
js