5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel mixで環境変数を.env以外のファイルから読み込む

Posted at

ステージング、本番サーバーにElasticbeanstalkを使っていて、ハマったのでメモ。

結論

https://laravel-mix.com/extensions/env-file
を使う。

// package.json
"scripts": {
        "local": "npm run development", // localは.envを読めばいいので上記使う必要なし
        "dev": "NODE_ENV=development ENV_FILE=./env/.env.staging node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", // デフォルトから変更。
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production ENV_FILE=./env/.env.production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
// webpack.mix.js
let mix = require('laravel-mix');
require('mix-env-file');

if(process.env.ENV_FILE) {
    mix.env(process.env.ENV_FILE);
}}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?