Code Monkey home page Code Monkey logo

laravel-elixir-env's Introduction

Laravel Elixir Env

NPM version

Use .env variables in your Javascript files with Webpack in Laravel Elixir.

Installation

npm install laravel-elixir-env --save

or

yarn add laravel-elixir-env

Requirements

  • Laravel Elixir
  • Laravel-elixir-webpack-official

Usage

Require the package in your gulpfile, after Elixir:

const elixir = require('laravel-elixir');

require('laravel-elixir-env');

Now you can access your variables in all the scripts that are packed with Webpack like so:

process.env.VAR_NAME

Optionally, you can set the path of the default .env file or set any dotenv configuration option like so:

require('laravel-elixir-env').config({ path: 'my-folder/.env' });

Be careful with sensitive variables that can hold private information. Don't forget to recompile on all your environments.

If you like this, please star on GitHub!

Issues and Pull Requests welcome.

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

Laravel-elixir-env is licensed under The MIT License (MIT).

laravel-elixir-env's People

Contributors

gizburdt avatar ovanschie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-elixir-env's Issues

Getting undefined for process.env.MY_ENV_VARIABLE

Hi, I'm trying to use this lib to get my Pusher key PUSHER_KEY from my .env file

Here is (part of) my gulpfile.js

var elixir = require('laravel-elixir');
require('laravel-elixir-env');
...
elixir(function(mix) {
    mix.webpack('echo.js','./resources/assets/js/');
});
...

My echo.js

import Echo from "laravel-echo"
console.log('PK:'+process.env.PUSHER_KEY);
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.PUSHER_KEY,
    cluster: 'eu',
    encrypted: true
});

gulp passes but I get console log: PK:undefined

If I console.log(process) I get some huge object with which I don't know what to do with or is there anywhere in it my PUSHER_KEY.

Thanks!

Security question

Hello. This is secure?
Someone's evil will get access to env vars in chrome debug tool with console log...or I have paranoia

Lack of "use strict" with "let, const, function, class"

Laravel's gulpfile.js ships with var elixir = require('laravel-elixir');, I've tested with both, but for the purpose of this issue, let the following be an example of my code from my gulpfile.js

const elixir = require('laravel-elixir');
require('laravel-elixir-env');

mix.webpack('app.js', 'public/assets/js/app.js');

Given that inside of my resources/assets/js/app.js file I have the following;

console.log(process.env(APP_URL))

With the following defined in my .env file:

APP_URL=http://<my_project>.dev

However, when running gulp from the command line, this is what I get:

/home/vagrant/www/<my_project>/node_modules/laravel-elixir-env/index.js:6
let envEntries = require('dotenv').config({ silent: true, path: envFile });
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

To solve this problem, simply "use strict"; at the top of laravel-elixir-env/index.js.

SytnaxError: Unexpected Token when Gulping

Hi there,

I installed the package according to the documentation, and when I ran Gulp I received the following error output in my terminal.

{path to modules}/node_modules/laravel-elixir-env/index.js:14
    config: function (options = {}) {
                              ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> ({path to gulp file}/gulpfile.js:5:1)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

I was able to get it working by removing the default value from the function, but I doubt that is a proper fix for the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.