Uso copy-webpack-plugin 10.2.0 y webpack 5.65.0. Quiero copiar el archivo js en la carpeta public/js a dist/js .
plugins: [ new CopyWebpackPlugin({ patterns:[ { from:'public/js/*.js', to:path.resolve(__dirname, 'dist','js'), } ] }) ], Pero la configuración también copia la ruta en dist, y se convierte en dist/js/public/js . Intento agregar flatten:true pero tiene un error
Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema. - options.patterns[0] has an unknown property 'flatten'. These properties are valid: object { from, to?, context?, globOptions?, filter?, transformAll?, toType?, force?, priority?, info?, transform?, noErrorOnMissing? }¿Cómo hacerlo entonces?
Puede establecer el nombre del archivo en el parámetro to usando los componentes [name] y [ext] y simplemente omitir la parte de la path .
plugins: [ new CopyWebpackPlugin({ patterns:[ { from:'public/js/*.js', to:path.resolve(__dirname, 'dist','js', '[name][ext]'), } ] }) ],