admin管理员组

文章数量:1290938

I have a .env file that contains the NODE_ENV variable. Per default, it is set to development. When building the React app with webpack, I launch the mand yarn build:

"scripts": {
    "start": "NODE_ENV=development webpack serve --open --hot",
    "build": "NODE_ENV=production && webpack",
}

The .envfile is:

NODE_ENV = "development"

But when logging the NODE_ENV value in my webpack configuration file, I can see it is still in development. The build is not minified either. But when I write production in my .env file, everything works fine.

The webpack configuration is:

/* eslint-env node */
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");

const isProductionMode = (mode) => mode === "production";

module.exports = () => {
  const env = require("dotenv").config({ path: __dirname + "/.env" });
  const nodeEnv = env.parsed.NODE_ENV;
  console.log("

本文标签: javascriptHow to change NODEENV when building app with webpackStack Overflow