How to use CopyWebpackPlugin to copy static assets

31 Views Asked by At

I'm using this configuration pattern:

new CopyWebpackPlugin({
    patterns: [{
        from: `src/assets/static/**/*`,
        to: 'dist',
    }]
})

But this results to

  • from -> src/assets/static/images
  • to-> dist/src/assets/static/images

Expected Output:

  • from -> src/assets/static/images
  • to-> dist/assets/static/images

Can anyone point out what am I doing wrong?

2

There are 2 best solutions below

0
IVO GELOV On

Have you tried this?

new CopyWebpackPlugin({
    patterns: [{
        context: './src/assets/static/images',
        from: './**/*',
        to: './assets/static/images',
    }]
});

Eventually you can try with to: './dist/assets/static/images'

1
Frank Dame On

Why don't you adjust the to configuration slightly.