I came across your post trying to figure out this same thing just now. I have my working solution below.
I added a GOOGLE_MAPS_API_KEY= key to my .env file and then added the envify to the transform option of elixir's browserify function:
var envify = require('envify/custom'); // replace process.env.* variables with strings
var envs = require('envs'); // optional but clean look for loading from process.env.*
dotenv = require('dotenv').config(); // load .env file (from / root) into process.env.* variable
elixir(function(mix) {
mix.less('app.less')
.browserify('app.js', null, null, { paths: 'vendor/laravel/spark/resources/assets/js', transform: [
[ envify({ GOOGLE_MAPS_API_KEY: envs('GOOGLE_MAPS_API_KEY', '123abcnotarealkey') }) ]
] })
.copy('node_modules/sweetalert/dist/sweetalert.min.js', 'public/js/sweetalert.min.js')
.copy('node_modules/sweetalert/dist/sweetalert.css', 'public/css/sweetalert.css');
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community