Skip to content

Commit 47c7bf6

Browse files
committed
feat: if isWatch and compilation complete watch file for changes and upload
1 parent 9e54e6d commit 47c7bf6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

webpack.config.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
1010
module.exports = async (env, argv) => {
1111
const isProduction = argv.mode === 'production'
1212
const isWatch = argv.watch === true;
13+
let isWatching = false
1314

1415
const config = {
1516
// Path to your entry point. From this file Webpack will begin his work
@@ -126,7 +127,6 @@ module.exports = async (env, argv) => {
126127
if (!isProduction) {
127128
config.plugins.push({
128129
apply: (compiler) => {
129-
// console.log('Webpack build is complete in development mode!');
130130
symlink('./dist', '../dist', 'dir')
131131
symlink('./node_modules/@cocreate/pwa/src/service-worker.js', '../service-worker.js', 'file')
132132
symlink('./node_modules/@cocreate/pwa/src/manifest.webmanifest', '../manifest.webmanifest', 'file')
@@ -136,7 +136,20 @@ module.exports = async (env, argv) => {
136136
}
137137

138138
if (isWatch) {
139-
upload(__dirname, ['../', '-w'])
139+
config.plugins.push({
140+
apply: (compiler) => {
141+
// Hook into the "emit" event, which occurs after the compilation is complete
142+
compiler.hooks.emit.tapAsync('watchFiles', (compilation, callback) => {
143+
if (!isWatching) {
144+
isWatching = true
145+
upload(__dirname, ['../', '-w'])
146+
}
147+
// Don't forget to call the callback function to signal completion
148+
callback();
149+
});
150+
}
151+
})
152+
// upload(__dirname, ['../', '-w'])
140153
}
141154

142155
return config;

0 commit comments

Comments
 (0)