@@ -16,7 +16,12 @@ const WebpackRTLPlugin = require('kolibri-tools/lib/webpackRtlPlugin');
1616
1717const { InjectManifest } = require ( 'workbox-webpack-plugin' ) ;
1818
19- // Function to detect if running in WSL
19+ const DEFAULT_WEBPACK_DEV_HOST = '127.0.0.1' ;
20+
21+ /**
22+ * Function to detect if running in WSL
23+ * @return {boolean }
24+ */
2025function isWSL ( ) {
2126 try {
2227 const version = fs . readFileSync ( '/proc/version' , 'utf8' ) ;
@@ -26,14 +31,24 @@ function isWSL() {
2631 }
2732}
2833
29- // Function to get WSL IP address
30- function getWSLIP ( ) {
34+ /**
35+ * Get the host for the webpack dev server.
36+ * @return {string }
37+ */
38+ function getWebpackDevHost ( ) {
39+ if ( process . env . WEBPACK_DEV_HOST ) {
40+ return process . env . WEBPACK_DEV_HOST ;
41+ }
42+
43+ if ( ! isWSL ( ) ) {
44+ return DEFAULT_WEBPACK_DEV_HOST ;
45+ }
46+
3147 try {
32- const ip = execSync ( 'hostname -I' ) . toString ( ) . trim ( ) . split ( ' ' ) [ 0 ] ;
33- return ip ;
48+ return execSync ( 'hostname -I' ) . toString ( ) . trim ( ) . split ( ' ' ) [ 0 ] ;
3449 } catch ( err ) {
3550 console . warn ( 'Failed to get WSL IP address:' , err ) ;
36- return '127.0.0.1' ;
51+ return DEFAULT_WEBPACK_DEV_HOST ;
3752 }
3853}
3954
@@ -60,11 +75,8 @@ module.exports = (env = {}) => {
6075 const pnpmNodeModules = path . join ( rootDir , 'node_modules' , '.pnpm' , 'node_modules' ) ;
6176
6277 // Determine the appropriate dev server host and public path based on environment
63- const isWSLEnvironment = isWSL ( ) ;
64- const devServerHost = isWSLEnvironment ? '0.0.0.0' : '127.0.0.1' ;
65- const devPublicPath = isWSLEnvironment ?
66- `http://${ getWSLIP ( ) } :4000/dist/` :
67- 'http://127.0.0.1:4000/dist/' ;
78+ const devServerHost = getWebpackDevHost ( ) ;
79+ const devPublicPath = `http://${ devServerHost } :4000/dist/` ;
6880
6981 const workboxPlugin = new InjectManifest ( {
7082 swSrc : path . resolve ( srcDir , 'serviceWorker/index.js' ) ,
@@ -120,10 +132,8 @@ module.exports = (env = {}) => {
120132 allowedHosts : [
121133 '127.0.0.1' ,
122134 'localhost' ,
123- ] . concat (
124- // For WSL, allow the WSL IP address
125- isWSLEnvironment ? [ getWSLIP ( ) ] : [ ]
126- ) ,
135+ getWebpackDevHost ( ) ,
136+ ]
127137 } ,
128138 module : {
129139 rules : [
0 commit comments