Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to copy an empty folder with webpack

Using Webpack and copy-webpack-plugin I need to copy an entire folder during build and I have:

plugins: [
  new CopyPlugin({
    patterns: [
      { from: './src/assets', to: './assets' }
    ]
  })
]

However this fails when the assets folder is empty:

ERROR: unable to locate ...

If I add one file to assets folder i will work.

How to solve this?

like image 281
Miguel Moura Avatar asked Sep 10 '20 15:09

Miguel Moura


1 Answers

Just add the property noErrorOnMissing to the patterns first object and set it to true. From what I understood, this will avoid generating an error if no file is present in the "from" destination folder, but at the same time it wont add the empty folder to your output folder (at least in my own test). This is the extract from one of my projects:

new CopyWebpackPlugin({
            patterns: [
                {
                    from: __dirname + '/src/assets/images',
                    to: 'assets/images',
                    noErrorOnMissing: true
                }
            ]
        })

Source: https://webpack.js.org/plugins/copy-webpack-plugin/#noerroronmissing

like image 92
Arturo Avatar answered Sep 30 '22 17:09

Arturo