3

I'm trying to disable the Vue Devtools in production so i want inside the app.js to check if the APP_ENV variable is equal to production.

What i have done so far:

Inside webpack.mix.js

require('dotenv').config(); 

Inside app.js

console.log(process.env.APP_ENV)//Undefined

if (process.env.APP_ENV === 'production') {
    Vue.config.devtools = false;
    Vue.config.debug = false;
    Vue.config.silent = true; 
}

Enviroment Variable

APP_ENV=production

I read the documentantion about adding MIX_APP_ENV so i can inject the variable inside webpack but it didn't also work.

Folder Structure:

d-----        01-Feb-21  10:31 PM                app
d-----        29-Jan-21  12:12 PM                bootstrap
d-----        29-Jan-21  12:12 PM                config
d-----        30-Jan-21  10:26 PM                database
d-----        16-Apr-21  10:49 PM                node_modules
d-----        29-Jan-21   1:14 PM                public
d-----        29-Jan-21  12:22 PM                resources
d-----        29-Jan-21  12:12 PM                routes
d-----        29-Jan-21  12:12 PM                storage
d-----        29-Jan-21  12:12 PM                tests
d-----        01-Feb-21   9:29 PM                vendor
-a----        29-Jan-21  12:12 PM            220 .editorconfig
-a----        16-Apr-21  10:45 PM            954 .env
-a----        29-Jan-21  12:14 PM            816 .env.example
-a----        29-Jan-21  12:12 PM            111 .gitattributes
-a----        29-Jan-21  12:12 PM            191 .gitignore
-a----        29-Jan-21  12:12 PM            181 .styleci.yml
-a----        29-Jan-21  12:12 PM           1686 artisan
-a----        01-Feb-21  10:41 PM           1793 composer.json
-a----        01-Feb-21  10:41 PM         282388 composer.lock
-a----        16-Apr-21  10:49 PM         531190 package-lock.json
-a----        16-Apr-21  10:49 PM           1103 package.json
-a----        29-Jan-21  12:12 PM           1202 phpunit.xml
-a----        29-Jan-21  12:12 PM           3780 README.md
-a----        29-Jan-21  12:12 PM            563 server.php
-a----        16-Apr-21  10:55 PM            578 webpack.mix.js
4
  • Have you rerun npm run watch after setting the MIX_APP_ENV? And in js it should still be process.env.MIX_APP_ENV? Commented Apr 16, 2021 at 19:50
  • Yes i have done that, i also used php artisan optimize to clear everything. Commented Apr 16, 2021 at 19:51
  • Can you share with us the project dir tree? Because Dotenv checks the application root dir and get that .env files, may be it is searching for a .env file from another dir, to check if a dir is a root you need to check if there is a package.json inside it. Commented Apr 16, 2021 at 19:53
  • I added the folder structure. @DaviMendesDev Commented Apr 16, 2021 at 19:58

1 Answer 1

2

I figured out that you need to re-run npm run watch if it is already running, that was the actual issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.