I have a problem with getting my mp3 files to work using the webpack file loader.
This is the issue:
I have a mp3 file on my harddisk, that if I open using chrome by for example "c:\somefolder\somemp3file.mp3" opens up in a tab in the browser and plays just fine.
However, when I serve the exact same file using webpack it does not work. I have configured the loader in webpack like this:
{
test: /\.(gif|jpg|png|mp3|aac|ogg)$/,
loader: 'file'
}
Then, when I'm trying to link to the file I require it inside my javascript, like this:
require('file!./../content/somemp3file.mp3');
this correctly returns me the url for the mp3 file.
If I try to manually go to localhost:8080
followed by the url returned by require, the mp3 player in Chrome pops up like I expect it to, but the file cannot be played, and it's not possible to click on the play button like the file is corrupted or something.
Anyone knows what I'm doing wrong here?
file!
when you callrequire()
. That actually causes a second.mp3
file to be generated, probably ~80bytes. If you look at the file it's just a module export of a string (URL to the actual.mp3
file that is bundled). So leave the webpack config as you have it, and in your js file,var src = require('./../content/somemp3file.mp3'); document.getElementById('myAudio').src = src;
– Cleaner