背景图片未显示

时间:2020-11-10 20:09:18

标签: reactjs webpack

我有这个webpack.config.js文件

const path = require('path');
module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist/assets'),
    filename: 'bundle.js',
  },
  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    publicPath: '/assets/',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [{
              loader: 'file-loader',
              options: {}
        }]
      },
    ],
  },
};

我的应用程序的文件结构如下:

dist
..assets
...bundle.js
..index.html
src
..components
..pages
..images
..App.js
..index.js
..style.css

我正在尝试使用css as设置页面的背景图像

[page-selector]{
 background: url('./images/someimage.jpg')
}

,但不显示。我怀疑这与映像的相对路径或适当的加载程序及其选项有关,但我不知道它到底是什么以及如何解决它。任何帮助将不胜感激。预先感谢

0 个答案:

没有答案