Laravel-mix: environment variables inside "webpack.mix.js" doesnt work anymore

Created on 1 Sep 2017  路  5Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: v1.4.2
  • Node Version v8.4.0
  • NPM Version v5.3.0
  • OS: OSX 10.11.6

Description:

using an evn variable no longer works on assets compilation, on older version of mix 0.11.4 it was working correctly.

Steps To Reproduce:

  • create a new folder and name it something like "resources/bulma/xxx.scss"
  • make an env var equal to that name "MIX_MM_FRAMEWORK=bulma"
  • compile against the env var name
mix.sass('resources/' + process.env.MIX_MM_FRAMEWORK + '/xxx.scss', 'public/assets/vendor/style.css')
    .version()

https://github.com/JeffreyWay/laravel-mix/issues/1096

Most helpful comment

@ctf0 BTW it looks like all you need to do is use the dotenv package yourself (already installed by Mix). For example, here's how i'm using it to define the Browsersync proxy URL for a WordPress theme:

let mix = require('laravel-mix');
require('dotenv').config();

let proxy_url = process.env.BROWSERSYNC_PROXY_URL || 'local.wordpress.dev';

// .. your mix configuration here...
    .browserSync({
        proxy: proxy_url,
    });

All 5 comments

duplicate of #1143

@ctf0 BTW it looks like all you need to do is use the dotenv package yourself (already installed by Mix). For example, here's how i'm using it to define the Browsersync proxy URL for a WordPress theme:

let mix = require('laravel-mix');
require('dotenv').config();

let proxy_url = process.env.BROWSERSYNC_PROXY_URL || 'local.wordpress.dev';

// .. your mix configuration here...
    .browserSync({
        proxy: proxy_url,
    });

@dabernathy89 focken AWESOME, many thanx.

hello there, can anyone tell me how to access the api key from .env file in a vue.js component in laravel mix, please see here: https://stackoverflow.com/questions/52353266/how-to-access-vue-js-api-key-in-laravel-application/52353392?noredirect=1#comment91651775_52353392 thanks

I could i never realize that just using process.env.APP_URL works! I'm using laravel-mix v4, no need to require dotenv

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sdebacker picture sdebacker  路  3Comments

mstralka picture mstralka  路  3Comments

RomainGoncalves picture RomainGoncalves  路  3Comments

wendt88 picture wendt88  路  3Comments

terion-name picture terion-name  路  3Comments