audio files in Next js #18852
-
How to add audio files in next js. i tried loader but its not working showing me error. Screenshot (90) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @khan03148. You can load audio files like this in your
module.exports = {
webpack(config, options) {
const { isServer } = options;
config.module.rules.push({
test: /\.(ogg|mp3|wav|mpe?g)$/i,
exclude: config.exclude,
use: [
{
loader: require.resolve('url-loader'),
options: {
limit: config.inlineImageLimit,
fallback: require.resolve('file-loader'),
publicPath: `${config.assetPrefix}/_next/static/images/`,
outputPath: `${isServer ? '../' : ''}static/images/`,
name: '[name]-[hash].[ext]',
esModule: config.esModule || false,
},
},
],
});
return config;
},
}; Also the |
Beta Was this translation helpful? Give feedback.
-
this solution broken after may helps someone on next.config.js/** @type {import('next').NextConfig} */
const config = {
...,
webpack:function(config,options){
config.module.rules.push({
test:/\.(mp4|mp3|ogv|oga|webm)$/i,
type: 'asset/resource',
generator: {
emit:true,
filename: (options.isServer?'../':'') + 'static/media/[name].[contenthash:8][ext]',
publicPath: (config.assetPrefix??config.basePath??'') + '/_next/static/media/',
}
});
return config;
}
};
module.exports = config; package.json{
...,
"scripts": {
"dev": "next dev",
"build:windows": "next build && xcopy \".next/server/static/media\" \"out/_next/static/media\" /S /I /Q /Y && explorer out",
"build:linux": "next build && cp --recursive --update \".next/server/static/media\" \"out/_next/static/media\""
},
...
} assets.d.tsdeclare module '*.bin' {
const src:string;
export default src;
};
declare module '*.dat' {
const src:string;
export default src;
};
declare module '*.mp4' {
const src:string;
export default src;
};
... |
Beta Was this translation helpful? Give feedback.
-
If it can help somebody, here's how I made it work with Next 15 To bundle PDF files inside the
Without the |
Beta Was this translation helpful? Give feedback.
Hi @khan03148. You can load audio files like this in your
next.config.js
:npm install file-loader url-loader --save-dev