T
T
thehighhomie2016-08-25 13:06:51
webpack
thehighhomie, 2016-08-25 13:06:51

Wepback: why NODE_ENV environment variable is undefined?

Somehow I started to deal with webpack but a lot of work appeared and I left it. Now back to this, and almost immediately I had a problem with the NODE_ENV change. I look at the screencasts of I. Kantor, here is the webpack.config.js code:

'use strict';

const NODE_ENV = process.env.NODE_ENV || 'development';
const webpack = require('webpack');

module.exports = {
  entry: './home',

  output: {
    filename: 'build.js',
    library: 'home'
  },

  watch: NODE_ENV == 'development',

  watchOptions: {
    aggregateTimeout: 100
  },

  devtool: NODE_ENV == 'development' ? 'cheap-inline-module-source-map' : null,

  plugins: [
    new webpack.EnvironmentPlugin('NODE_ENV', 'USER')
  ]
};

when you enter the command NODE_ENV=development into the console, webpack reports that "NODE_ENV" is not an internal or external
command, operable program or batch file.
When starting webpack, it says:
WARNING in NODE_ENV environment variable is undefined.
WARNING in NODE_ENV environment variable is undefined.
What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pianist, 2016-09-06
@thehighhomie

This is how it works for me:

const NODE_ENV = process.env.NODE_ENV || 'development';
...
plugins: [
        new webpack.DefinePlugin({
            NODE_ENV: JSON.stringify(NODE_ENV)
        })
    ],

Windows 10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question