我正在尝试在使用Webpack的应用程序中加载简短的mp3文件。但是我无法正常工作。这是我得到的错误。
HTTP load failed with status 404. Load of media resource http://127.0.0.1:5000/dist022e7b776a752949ddcf677722cde8fb.mp3 failed.
这是我的webpack.congfig
var path = require('path');
var webpack = require('webpack');
var CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
index: './js/index.js',
topics: './js/topics.js',
plans: './js/plans.js',
audio_processor: './js/audio_processor.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
publicPath: '/dist'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(scss)$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(ogg|mp3|wav|mpe?g)$/i,
use: 'file-loader'
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
JQuery: 'jquery'
}),
new CleanWebpackPlugin()
]
};
这就是我尝试访问文件的方式。
let click_sound = require('../audio/click_sound.mp3');
let audio = new Audio(click_sound);
这是文件夹结构。看来可以在dist文件夹中创建mp3了。我正在尝试从audio_recorder.js文件访问mp3文件。
|-- audio
| `-- click_sound.mp3
|-- css
| |-- bootstrap.css
| |-- main.css
| `-- starter-template.css
|-- dist
| |-- 022e7b776a752949ddcf677722cde8fb.mp3
| |-- audio_processor.bundle.js
| |-- index.bundle.js
| |-- plans.bundle.js
| `-- topics.bundle.js
|-- js
| |-- PlaybackController.js
| |-- audio_processor.js
| |-- audio_recorder.js
| |-- config.json
| |-- index.js
| |-- lesson_feedback.js
| |-- lesson_notation.js
| |-- plans.js
| `-- topics.js
谢谢