اذهب إلى المحتوى
  • 0

معالجة ملفات mp3 في Webpack 5 / Next.js

عبد النور محمد

السؤال

أنا أعمل حاليًا مع next@11.1.2 و webpack v5 وتعطلت لساعات مع إصلاح تحميل mp3. لقد جربت العديد من الحلول لم يعمل أي منهم من أجلي.

Type error: Cannot find module 'public/sounds/bighit.mp3' or its corresponding type declarations.

  14 | 
  15 | // Assets
> 16 | import sound_bighit from "public/sounds/bighit.mp3"
     |                          ^
info  - Checking validity of types .%     
onst path = require('path')
const SRC = path.resolve(__dirname, 'public/sounds/')

module.exports = {
    webpack: (config, { }) => {

        config.module.rules.push({
            test: /\.mp3$/,
            incluse: SRC,
            use: {
                loader: 'file-loader',
                options: {
                    name: '[name].[contenthash].[ext]',
                    outputPath: 'public/sounds/',
                    publicPath: 'public/sounds/'
                }
            }

        })

        // config.module.rules.push({
        //     test: /\.mp3$/,
        //     use: {
        //         loader: 'file-loader',
        //     },
        // })

        // config.module.rules.push({
        //     test: /\.mp3/,
        //     use: {
        //         loader: 'url-loader',
        //     },
        // })

        return config
    }
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

ليست هناك حاجة لاستيراد مثل هذه الملفات. يدعم Next.js وضع الملفات في المجلد العام (assets in public). قم بإزالة تكوين webpack المخصص الخاص بك ، ثم قم بفعل التالي

<audio controls src="/sounds/bighit.mp3" />

أيضًا ، الخطأ الذي كنت تحصل عليه كان خطأ TypeError ، لإصلاحه يمكنك محاولة:

declare module "*.mp3" {
  const content: string;
  export default content;
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...