1

I'm writing a TypeScript application using Webpack and file-loader for serving images and audio. I can't get the webpack config to work with audio files.

Im getting GET http://localhost:8080/media/d.mp3 404 (Not Found)

The images work fine on the dev server and also build fine with the webpack setup below.

Folder structure:

|-public    
|---audio    
|---images    
|-src    
|---audio    
|---images

Same result if I combine all extensions into one string and use a single folder.

My webpack.config.js:

const path = require('path');

module.exports = {
    entry: "./src/index.ts",
    output: {
        path: path.resolve(__dirname, 'public/scripts'),
        filename: 'bundle.js'
    },
    devtool: "source-map",
    module: {
        rules: [{
                test: /\.tsx?$/,
                loader: "awesome-typescript-loader"
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.(scss|sass|css)$/,
                exclude: /node_modules/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',                            
                            outputPath: '../images/',
                            publicPath: 'images/',
                            useRelativePaths: true
                        }
                    }
                ]
            },
            {
                test: /\.(mp3|wav)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {                            
                            name: '[name].[ext]',                            
                            outputPath: '../audio/',
                            publicPath: 'audio/',
                            useRelativePaths: true
                        }
                    }
                ]
            },
        ]
    },
    resolve: {
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    devServer: {
        contentBase: path.resolve(__dirname, 'public'),
        publicPath: '/scripts/'
    },
    node: {
        fs: "empty"
    }
};
Karol Skrobot
  • 450
  • 3
  • 19
  • Is there anything at http://localhost:8080/audio/d.mp3? – meyi Jun 25 '19 at 20:38
  • no there wasn't. but when I deleted the build folder, before I built everything afresh neither was anything in localhost:8080/images folder. So when I physically copied the audio files from src/audio to build/audio and then built again everything started working. i'm probably configuring paths incorrectly but I'm still puzzled why it would emit image files but not audio files – Karol Skrobot Jun 25 '19 at 21:06
  • This may seem futile, but I've had some weird things with paths before. For each publicPath, try adding ./ to the beginning of the path. – meyi Jun 25 '19 at 21:11
  • @meyi yep. makes no difference – Karol Skrobot Jun 25 '19 at 21:15

0 Answers0