output
    output: {
        path: config.build.assetsRoot,
        publicPath: process.env.NODE_ENV === 'production' ? 
        config.build.assetsPublicPath : config.dev.assetsPublicPath,
        filename: '[name].js'
    }
base
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
    productionSourceMap: false,
    productionGzip: false,
    productionGzipExtensions: ['js', 'css']
  },
after build,the index pages work normal, css background-image path like this
background: url(./static/img/bg_certificate.c5cad1e.png) no-repeat 50%;
but the component css background-image path error, like this
background: url(static/img/btn_my.b9186cc.png) no-repeat 50%;
It's look like the path lose "./",
Instead of absolute path, You should give the relative path from the current file location with webpack in .vue file, something like:
background: url(../../static/img/btn_my.b9186cc.png) no-repeat 50%;
                        I also come by this issue when I tried using styles in component of Vue 3. I solved it by using the following syntax.
background-image: url('~@/assets/image.png');
                        What about setting:
build: {
  ...
  assetsSubDirectory: '',
  assetsPublicPath: '/static/',
  ...
}
and so:
background: url(/static/img/btn_my.b9186cc.png) no-repeat 50%;
Working with relative paths is, in general lines, a nightmare.
:style="{ backgroundImage: 'url(\'' + require('@/assets/bg3.jpg') + '\')' }
This will be the Best solution for the background image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With