Serving mp3 files using the webpack file loader

后端 未结 5 506
名媛妹妹
名媛妹妹 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:14

    https://stackoverflow.com/a/41158166/11878375 - it's correctly answer, but define SRC like this:

    var path = require('path');
    
    var SRC = path.resolve(__dirname, 'src/main/js');
    

    For example, I am using react-chat-ui with webpack and this is my webpack.config.js:

    const path = require('path');
    
    const SRC = path.resolve(__dirname, 'node_modules');
    
    module.exports = {
      entry: './jsx/App.jsx',
      mode: "development",
      output: {
        path:
            '/java/helios-backend/src/main/resources/static/js'
            // __dirname + '/js/'
        ,
        filename: 'bundle.js'
      },
      devtool: '#sourcemap',
      stats: {
       colors: true,
       reasons: true
      },
      module: {
        rules: [
          { test: /\.css$/, loader: 'style-loader!css-loader' },
          {
            test: /\.jsx?$/,
            exclude: /(node_modules)/,
            loaders: ['babel-loader']
          },
          {
            test: /\.(gif|png|jpe?g|svg)$/i,
            use: [
              'file-loader',
              {
                loader: 'image-webpack-loader',
                options: {
                  bypassOnDebug: true,
                  disable: true, 
                },
              },
            ]},
          {
            test: /\.mp3$/,
            include: SRC,
            loader: 'file-loader'
          }
    
        ]
      }
    };
    

    And do not forget to install the file-loader before:

    npm install file-loader --save-dev
    

提交回复
热议问题