joshwcomeau / use-sound

A React Hook for playing sound effects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use in a bundle made by webpack

Ofer-Gal opened this issue · comments

Webpack is complaining:
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

Any Idea what I can do?

Are you using nextjs?

I had the same problem. You can create a next.js.config file in your project root with the code:

  webpack(config, options) {
    const { isServer } = options
    config.module.rules.push({
      test: /\.(mp3)$/,
      use: {
        loader: 'file-loader',
        options: {
          publicPath: '/_next/static/sounds/',
          outputPath: 'static/sounds/',
          name: '[name].[ext]',
          esModule: false
        }
      }
    })

    return config
  }
}

you can see more details here:

vercel/next.js#12810

I added some more info about this to the README: https://github.com/joshwcomeau/use-sound#importingsourcing-audio-files

Hope it helps!

Thank you