diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /scripts/frontend | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'scripts/frontend')
-rwxr-xr-x | scripts/frontend/webpack_dev_server.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/frontend/webpack_dev_server.js b/scripts/frontend/webpack_dev_server.js new file mode 100755 index 00000000000..8026a8d47e2 --- /dev/null +++ b/scripts/frontend/webpack_dev_server.js @@ -0,0 +1,68 @@ +const nodemon = require('nodemon'); + +const DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost'; +const DEV_SERVER_PORT = process.env.DEV_SERVER_PORT || '3808'; +const STATIC_MODE = process.env.DEV_SERVER_STATIC && process.env.DEV_SERVER_STATIC != 'false'; +const DLL_MODE = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL != 'false'; + +const baseConfig = { + ignoreRoot: ['.git', 'node_modules/*/'], + noUpdateNotifier: true, + signal: 'SIGTERM', + delay: 1000, +}; + +// run webpack in compile-once mode and watch for changes +if (STATIC_MODE) { + nodemon({ + exec: `rm -rf public/assets/webpack ; yarn run webpack && exec ruby -run -e httpd public/ -p ${DEV_SERVER_PORT}`, + watch: [ + 'config/webpack.config.js', + 'app/assets/javascripts', + 'ee/app/assets/javascripts', + // ensure we refresh when running yarn install + 'node_modules/.yarn-integrity', + ], + ext: 'js,json,vue', + ...baseConfig, + }); +} + +// run webpack through webpack-dev-server, optionally compiling a DLL to reduce memory +else { + let watch = ['config/webpack.config.js']; + + // if utilizing the vendor DLL, we need to restart the process when dependency changes occur + if (DLL_MODE) { + watch.push( + 'config/webpack.vendor.config.js', + // ensure we refresh when running yarn install + 'node_modules/.yarn-integrity', + 'package.json', + 'yarn.lock', + ); + } + nodemon({ + exec: 'webpack-dev-server --config config/webpack.config.js', + watch, + ...baseConfig, + }); +} + +// print useful messages for nodemon events +nodemon + .on('start', function() { + console.log(`Starting webpack webserver on http://${DEV_SERVER_HOST}:${DEV_SERVER_PORT}`); + if (STATIC_MODE) { + console.log('You are starting webpack in compile-once mode'); + console.log('The JavaScript assets are recompiled only if they change'); + console.log('If you change them often, you might want to unset DEV_SERVER_STATIC'); + } + }) + .on('quit', function() { + console.log('Shutting down webpack process'); + process.exit(); + }) + .on('restart', function(files) { + console.log('Restarting webpack process due to: ', files); + }); |