Reputation: 20348
I have two project folders in the same parent folder. One is for front end files (JS, CSS, images etc.) and another is for the backend files. The frontend project uses webpack to build files into a dist folder. The backend project is the one which gets deployed to the server (or run on localhost).
So everytime I make change to a JS or CSS file, I run webpack build, copy the build files from frontend-project/dist
folder to backend/frontend/js
or backend/frontend/css
folder and rerun the backend project.
This is really counter-productive. I want to copy the dist files automatically after build to the backend-project
. Is there any way to do it in webpack using a plugin or without using one? I have used gulp for such kind of tasks before, but want to rely solely on webpack for now.
I tried the copy-webpack-plugin, but it doesn't run after the build, thus is not useful for me.
Upvotes: 5
Views: 5310
Reputation: 5179
I see several ways how to reach your purposes:
backend/frontend/js
folder as an output folder for your bundles.module.exports = {
//...
output: {
path: path.resolve(__dirname, '../backend/frontend')
}
};
FileManagerPlugin
to copy your bundle files to the backend after finishing of the build.module.exports = {
//...
plugins: [
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{
source: path.join(__dirname, 'dist'),
destination: path.join(__dirname, '../backend/frontend')
}
]
}
}
})
]
};
webpack-dev-server
to run build automatically when you develop. It doesn't store bundles in the file system, it keeps them in memory.Upvotes: 9