DOT files are always treated as directories.
{from: path.resolve(__dirname, 'application/admin/.htaccess'), to: 'admin/.htaccess', toType: 'file'}
will result in a folder /admin/.htaccess/ being created when a file /admin/.htaccess should be created. If the "to" is changed to something like 'admin/zzz.htaccess' then it creates it as a file. It appears that the "toType" is ignored if it has a leading dot.
This is more related to the missing file extension I guess, but nevertheless buggy
Closed this issue, because it will be fix after update loader-utils and we already have issue about this https://github.com/webpack-contrib/copy-webpack-plugin/issues/117
This is still not working
@pgilad it can be fixed only in major version :disappointed:
I understand, but this bug is from aug 2017, was closed 3 months ago and it wasn't fixed. So I recommend opening it (Because it's still relevant) and perhaps providing an alternative solution 馃槃
edit: what's wrong with releasing a major version?
@pgilad we already have issue https://github.com/webpack-contrib/copy-webpack-plugin/issues/117.
Too little time and a lot of work, if you wanna help feel free to PR:
webpack-default (https://github.com/webpack-contrib/copy-webpack-plugin/pull/146)For people googling for this issue and came on this.
If you have updated the plugin and having this issue you're probably adding to the config the to key which is causing to spawn a folder called .htaccess at the root of the build directory (or whatever dot file you're trying to copy).
If your dot file needs to sit at the root then it gets a bit counter-intuitive: your config should have only the from key pointing to your dot file.
This works:
new CopyWebpackPlugin([
{
from: './src/static/.htaccess',
},
]);
This for example will copy the file at the <build folder>/server/root/.htaccess:
new CopyWebpackPlugin([
{
from: './src/static/.htaccess',
to: 'server/root',
},
]);
This however DOES NOT work:
new CopyWebpackPlugin([
{
from: './src/static/.htaccess',
to: '.htaccess',
},
]);
Hope that clears things a little bit
Very strange that adding to only makes a directory for files _without_ an extension. If the files have an extension, then including to has no effect.
new CopyPlugin({
patterns: [
{from: 'public/foo.js'}, // Copies to /foo.js
{from: 'public/bar.js', to: 'bar.js'}, // Copies to /bar.js
{from: 'public/foo'}, // Copies to /foo
{from: 'public/bar', to: 'bar'}, // Unexpectedly creates a directory. Copies to /bar/bar
],
}),
Most helpful comment
For people googling for this issue and came on this.
If you have updated the plugin and having this issue you're probably adding to the config the
tokey which is causing to spawn a folder called.htaccessat the root of the build directory (or whatever dot file you're trying to copy).If your dot file needs to sit at the root then it gets a bit counter-intuitive: your config should have only the
fromkey pointing to your dot file.This works:
This for example will copy the file at the
<build folder>/server/root/.htaccess:This however DOES NOT work:
Hope that clears things a little bit