Home > Enterprise >  How do I set the target path in the copyfiles method with webpack in a Symfony project?
How do I set the target path in the copyfiles method with webpack in a Symfony project?

Time:01-24

Following these instructions I have been able to copy files from their location and into the relative output directory.

.setOutputPath('public/assets/@BUILDNUMBER@')
.copyFiles({
    from: './assets/images/favicon',
})

The docs go on to explain there is an optional "to" target path which I want to be "/images/favicon" (so the whole output path would be public/assets/@BUILDNUMBER@/images/favicon) but the way I'd expect to write this out creates errors when I run webpack.

.setOutputPath('public/assets/@BUILDNUMBER@')
.copyFiles({
    from: './assets/images/favicon',
    to: 'images/favicon'
})

Conflict: Multiple assets emit different content to the same filename images/favicon. Original source assets/images/favicon/ms-icon-150x150.png

I'll note that currently the auto-generated @BUILDNUMBER@ directory has an images subdirectory but not a favicons subdirectory, I have also tried pointing to the already existing images directory instead but it produces this error:

Error: EISDIR: illegal operation on a directory, open '/opt/my-site/public/assets/@BUILDNUMBER@/images'

So how can I set my copyFiles "to" path to point to public/assets/@BUILDNUMBER@/images or public/assets/@BUILDNUMBER@/images/favicon?

CodePudding user response:

I think you're missing the placeholders in the "to" parameter.

See the error message:

Conflict: Multiple assets emit different content to the same filename images/favicon

Webpack thinks "images/favicon" is the filename.

Maybe try this:

.copyFiles({
    from: './assets/images/favicon',
    to: 'images/favicon/[path][name].[ext]'
})

Here's a list of supported placeholders: https://github.com/webpack-contrib/file-loader#placeholders

If you're using versioning (.enableVersioning()) e.g. you have to add the hash as well:

.copyFiles({
    from: './assets/images/favicon',
    to: 'images/favicon/[path][name].[hash:8].[ext]'
})
  • Related