Serving mp3 files using the webpack file loader

后端 未结 5 544
名媛妹妹
名媛妹妹 2020-12-31 01:57

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 c

5条回答
  •  误落风尘
    2020-12-31 02:36

    My solution: install the file-loader. Update webpack.config.js:

    // webpack.config.js
    rules: [
                {
                    test: /\.mp3$/,
                    loader: 'file-loader',
                    options: {
                        name: '[path][name].[ext]'
                    }
                }
    

    Project.js :

    const smthn = require('../sound.mp3');
    const sound = new Audio('./sound.mp3');
    (() => sound.play())();
    

提交回复
热议问题