Webpack - background images not loading

后端 未结 8 1877
渐次进展
渐次进展 2020-12-09 15:34

I\'m fairly new to webpack but having some problems with css-loader or file-loader.

I\'m trying to load a background-image but it doesn\'t work quite right. The bac

8条回答
  •  无人及你
    2020-12-09 16:03

    Please try using, for example:

    html {
       background: url(~/Public/img/bg.jpg) no-repeat center center fixed; 
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: cover;
    }
    

    css-loader in webpack:

    {
        test: /\.(css|eot|svg|ttf|woff|jpg|png)$/i,
        use: ExtractTextPlugin.extract({
            use: [{
                loader: 'css-loader',
                options: {
                    importLoaders: 1,
                    minimize: true
                },
            }],
        }),
    },
    

    Result in bundle.css is:

    html{background:url(/Public/img/bg-picking.jpg) no-repeat 50% fixed;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover}
    

提交回复
热议问题