markotitel
5 months ago
43
0
Mix

Getting Object in the place of ENV var at build time.

Posted 5 months ago by markotitel

Hello. This is part of the code of the js file which is being compiled.

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':' + process.env.MIX_BROADCAST_PORT
});

The issue is that if this MIX_BROADCAST_PORT var is not defined the compiled code is like this.

window.Echo = new __WEBPACK_IMPORTED_MODULE_0_laravel_echo___default.a({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':' + Object({"NODE_ENV":"development"}).MIX_BROADCAST_PORT
});

If I define that ENV var even without a value. The code compiles fine ending up like this.

window.Echo = new __WEBPACK_IMPORTED_MODULE_0_laravel_echo___default.a({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':'});

What is the catch here? =)

Please sign in or create an account to participate in this conversation.