Copy-webpack-plugin: How can I use a template to copy files and keep the directory structure

Created on 15 Mar 2018  Β·  5Comments  Β·  Source: webpack-contrib/copy-webpack-plugin

I would like to know how to use a template to copy files and keep the file directory structure, thanks.

The desired result

β”œβ”€β”€β”€directory
β”‚ β”œβ”€β”€β”€directoryA
β”‚ β”‚ └───a.js
β”‚ β”‚ └───b.js
β”‚ β”œβ”€β”€β”€c.js

to

β”œβ”€β”€β”€directory
β”‚ β”œβ”€β”€β”€directoryA
β”‚ β”‚ └───a.hash.js
β”‚ β”‚ └───b.hash.js
β”‚ β”œβ”€β”€β”€c.hash.js

now after use toType:template i got

β”œβ”€β”€β”€directory
β”‚ └───a.hash.js
β”‚ └───b.hash.js
β”‚ └───c.hash.js

Needs more info

Most helpful comment

@lewayjack try lib/[path][name].[hash].[ext]

All 5 comments

@lewayjack don't use toType:template, just use glob and set fromArgs needed root directory

@evilebottnawi Sorry I may not express myself clearly.
i'd like to:

  1. Copy files from directory A to directory B
  2. Add hash value to file names
  3. Keep origin folder structure
    I do not quite understand how fromArgs adds hash value to the file name
    here is my code
      new CopyWebpackPlugin([
        {
          from: path.resolve(__dirname, '../app/web/assets/lib'),
          to: 'lib/[name].[hash].[ext]',
          toType: 'template'
        }
      ])

now all files are in the lib folder, not their own subdirectory

@lewayjack try lib/[path][name].[hash].[ext]

@ioannisNoukakis that works,THX

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BoldBigflank picture BoldBigflank  Β·  6Comments

smashercosmo picture smashercosmo  Β·  6Comments

niksmac picture niksmac  Β·  3Comments

jbruni picture jbruni  Β·  3Comments

serut picture serut  Β·  3Comments