My entry point is inside the directory that has been copied. This plugin seems to use the webpack file emit at the end to output the files. Is there a way to do this sooner? Or to somehow target an entrypoint inside the copied directory?
cp src/* dist/* && webpack
Sry, this plugin is an integration of cp for webpack during runs, there is no way to start/use a webpack plugin without actually starting webpack
But you could hook into the compilation process before entrypoints are resolved. I ended up doing it like this:
const EventHooksPlugin = require('event-hooks-webpack-plugin');
const fs = require('fs-extra')
//in webpack plugins
new EventHooksPlugin({
'before-run': (compilation, done) => {
console.log('Copying source files to compiled')
fs.copy('src', 'compiled', done);
}
}),
Sry, I overread entrypoints :), (maybe) possible, but not supported atm
@light24bulbs Thank you, your comment helped out a lot!
@evilebottnawi
It would be nice to have an option like event (either in options or pattern config) which will decide when the copy is executed.
PR welcome
I would love to see this as a simple option to copy-webpack-plugin as well rather than a more complicated hook.
Our scenario is as follows. We have a stand alone web project that acts as a host for a playground to design components. For the webpack dev server to work the dist folder needs to be relative. But for the production build (or actually after it) i want to copy the output to another folder where a different web server will serve the files.
The structure looks like.
\build -- Production web server serves from here
\components-web\ -- stand alone webpack dev server project.
\components-web\src\ --main source
\components-web\dist -- webpack output directory
Basically i just need to copy \components-web\dist to \build after the build is done.
Setting the output path to this works for the prod build but will also break the webpack dev server. I believe because it changes the relative path. Really the better approach is to copy after the build though.
config.output = {
path: __dirname + '/../build/dist',
}
Most helpful comment
But you could hook into the compilation process before entrypoints are resolved. I ended up doing it like this: