<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>react on Tom Roth</title><link>https://tomroth.dev/tags/react/</link><description>Recent content in react on Tom Roth</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 04 Nov 2019 00:00:00 +0000</lastBuildDate><atom:link href="https://tomroth.dev/tags/react/index.xml" rel="self" type="application/rss+xml"/><item><title>Playing a sound file with React and Webpack</title><link>https://tomroth.dev/react-sound/</link><pubDate>Mon, 04 Nov 2019 00:00:00 +0000</pubDate><guid>https://tomroth.dev/react-sound/</guid><description>One Link to heading Get the sound file you want (e.g. sound.mp3) and put it somewhere in your src directory.
Two Link to heading Add this to your webpack.config.js file. Make sure you have file-loader installed (run npm install --save-dev file-loader if you don’t.)
{ test: /\.mp3$/, loader: &amp;#39;file-loader&amp;#39;, query: { name: &amp;#39;static/media/[name].[hash:8].[ext]&amp;#39; } } Three Link to heading Import the file at the top of your JavaScript file. Put the path relative to the JavaScript file you are loading the sound from.</description></item></channel></rss>