copy-webpack-plugin: Does not copy files to actual output folder when webpack-dev-server is used
It appears that nothing happens when trying to copy some extra files (not bundled) to the output folder, under the webpack-dev-server
logic:
devServer: {
contentBase: './public',
outputPath: path.resolve(ROOT_PATH, 'public'),
historyApiFallback: true,
hot: true,
inline: true,
port: 33000,
progress: true
},
plugins: [
new CopyWebpackPlugin([
{from: 'src/css', to: 'css', force: true},
{from: 'src/img', to: 'img', force: true}
]),
new webpack.HotModuleReplacementPlugin(),
new OpenBrowserPlugin({url: 'http://localhost:33000'})
]
Can this be done somehow? The webpack-dev-server needs this to show some external CSS and IMAGE files. I used to be doing this with gulp
but now I want to get rid of this dependency.
Using your plugin with the simple webpack (for build
) works perfectly but not for webpack-dev-server
.
NOTE: I can achieve what I want if I use both webpack
and webpack-dev-server
on the start
script, but this is not too elegant and done only for solving this problem:
"scripts": {
"build": "webpack",
"start": "npm run build && webpack-dev-server"
},
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 40
- Comments: 48 (6 by maintainers)
Commits related to this issue
- remove platform specific separators from compilation.asset keys, fixes #29 — committed to matus-m/copy-webpack-plugin by matus-m 8 years ago
- remove platform specific separators from compilation.asset keys, fixes #29 — committed to matus-m/copy-webpack-plugin by matus-m 8 years ago
- added write-file-webpack-plugin: https://github.com/webpack-contrib/copy-webpack-plugin/issues/29 — committed to prusswan/learn-d3 by prusswan 5 years ago
- Re-Activate fonts Remove commented-out fonts from custom.scss Add webpack configuration to leave `url` statements on CSS alone. Add webpack plugin to copy the `public` directory into `dist`. If th... — committed to wmde/fundraising-application by gbirke 3 years ago
- Re-Activate fonts Remove commented-out fonts from custom.scss Add webpack configuration to leave `url` statements on CSS alone. Add webpack plugin to copy the `public` directory into `dist`. If th... — committed to wmde/fundraising-app-frontend by gbirke 3 years ago
I had the same problem with v4.0.1 (files not copied to output folder).
After seeing the Breaking Change described at v3, I was able to fix the problem by adding the
WriteFileWebpackPlugin
to my webpack config(an alternative for those not wishing to revert back to v2.1.6)
This isn’t a bug, as explained in the FAQ. You must include the write-file-webpack-plugin to write files use webpack-dev-server.
I was broken on “4.0.0”, so I rolled back to “2.1.6”.
copy-webpack-plugin “2.1.6” works with webpack-dev-server:
css assets are now copied to my /dist folder when I use webpack-dev-server with “copy-webpack-plugin”.
Suggestion:
Maybe the fix that was added in 2.1.6 got removed, because someone didn’t know why it was needed, so diff “2.1.6” and “4.0.0” and see what changed.
Hey guys! This functionality seems to be broken in 3.0.1. Does not work for me with webpack-dev-server even under OS X with a very simple setup and an example from README.md. Works well with just webpack though.
This is my webpack.config.js:
Images are not copied to “build” directory. It is not even created when starting webpack-dev-server.
I have just tested with version 2.1.6 and confirm that it works both with webpack and webpack-dev-server.
Hope it’ll save someone some time. 😃
This worked for me
new CopyPlugin([ { from: path.join(__dirname, "src", "*.html"), to: path.join(__dirname, "dist", "[name].html") } ])
@DevidCIC Did you manage to resolve the issue? It’s not copying anything for me
I am using:
I tried the solution from @sfletche and on my localhost under assets I see the monaco folder, but on dev-server the monaco folder is not there and therfore the monaco-editor is not loading.
This is my webpack.common configuration:
new WriteFilePlugin(), new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets' }, { from: 'src/meta' }, { from: 'node_modules/ngx-monaco-editor/assets/monaco', to: 'assets/monaco/', } ], isProd ? { ignore: ['mock-data/**/*'] } : undefined ),
This is what I see when running localhost: https://i.stack.imgur.com/qDlNA.png
And when I run dev-server the folder is missing for some reason: https://i.stack.imgur.com/PwtYV.png
Any suggestions ?
Broken for me as well in 4.0.1 with dev-server. Rolling back to 2.1.6 fixes the issue.
This is what I was referring to: https://github.com/kevlened/copy-webpack-plugin/pull/71/files
I see now that they are suggesting using write-webpack-plugin which does not work for you. I assume that using older version of the plugin does not work either, is it correct?
This is my webpack config from the project I was referring to previously:
Dependencies:
It works both with webpack and webpack-dev-server.
Could you please check this setup? I can’t see that it is hacky in any way (I am very keen on well-configured projects). If it works for you then you may be able to integrate it smoothly in your project’s configuration.
Good luck!
I’ve removed the
copy-webpack-plugin
from my project completely and used a basic shell script inside the package.json. I made a new Phoenix starter project with it (Phoenix, Webpack, Stylus, React and Hot Module Replacement): Webpacker. Works nicely.I can’t believe I wasted so much time with something a small shell script can do.
@szubtsovskiy, thanks again for your heads-up!
this worked for me
to
Change the
./build/pdfexpress/
portion with your distribution (dist) folderTry enabling
debug
to see where the latest version is putting the files incompilation.assets
.