process.env.NODE_ENV = 'production'

在node中,有全局变量process表示的是当前的node进程。

process.env包含着关于系统环境的信息。但是process.env中并不存在NODE_ENV这个东西。

NODE_ENV是用户一个自定义的变量,在webpack中它的用途是判断生产环境或开发环境的依据的。

为了查看 process的基本信息, 新建一个 process.js 文件,在里面加一句代码:console.log(process.env);

终端中执行 node process.js 可以在命令行中打印如下信息:

{ ALLUSERSPROFILE: 'C:\\ProgramData',
  APPDATA: 'C:\\Users\\hyx\\AppData\\Roaming',
  CommonProgramFiles: 'C:\\Program Files\\Common Files',
  'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
  CommonProgramW6432: 'C:\\Program Files\\Common Files',
  COMPUTERNAME: 'DESKTOP-6900FKS',
  ComSpec: 'C:\\WINDOWS\\system32\\cmd.exe',
  DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
  HOMEDRIVE: 'C:',
  HOMEPATH: '\\Users\\hyx',
  LOCALAPPDATA: 'C:\\Users\\hyx\\AppData\\Local',
  LOGONSERVER: '\\\\DESKTOP-6900FKS',
  NODE_ENV: 'production',
  NUMBER_OF_PROCESSORS: '4',
  NVM_HOME: 'F:\\nvm\\nvm',
  NVM_SYMLINK: 'C:\\Program Files\\nodejs',
  OneDrive: 'C:\\Users\\hyx\\OneDrive',
  OS: 'Windows_NT',
  Path:
   'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;F:\\Git\\cmd;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;F:\\nvm\\nvm;C:\\Program Files\\nodejs;;F:\\Microsoft VS Code\\bin;C:\\Users\\hyx\\AppData\\Roaming\\npm;C:\\Users\\hyx\\AppData\\Local\\Microsoft\\WindowsApps;F:\\nvm\\nvm;C:\\Program Files\\nodejs',
  PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
  PROCESSOR_ARCHITECTURE: 'AMD64',
  PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 60 Stepping 3, GenuineIntel',
  PROCESSOR_LEVEL: '6',
  PROCESSOR_REVISION: '3c03',
  ProgramData: 'C:\\ProgramData',
  ProgramFiles: 'C:\\Program Files',
  'ProgramFiles(x86)': 'C:\\Program Files (x86)',
  ProgramW6432: 'C:\\Program Files',
  PROMPT: '$P$G',
  PSModulePath: 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\',
  PUBLIC: 'C:\\Users\\Public',
  SESSIONNAME: 'Console',
  SystemDrive: 'C:',
  SystemRoot: 'C:\\WINDOWS',
  TEMP: 'C:\\Users\\hyx\\AppData\\Local\\Temp',
  TMP: 'C:\\Users\\hyx\\AppData\\Local\\Temp',
  USERDOMAIN: 'DESKTOP-6900FKS',
  USERDOMAIN_ROAMINGPROFILE: 'DESKTOP-6900FKS',
  USERNAME: 'hyx',
  USERPROFILE: 'C:\\Users\\hyx',
  windir: 'C:\\WINDOWS',
  TERM_PROGRAM: 'vscode',
  TERM_PROGRAM_VERSION: '1.41.1',
  LANG: 'zh_CN.UTF-8',
  COLORTERM: 'truecolor' }

打印process, console.log(process):

process {
  title: '  - node  process.js',
  version: 'v10.16.0',
  versions:
   { http_parser: '2.8.0',
     node: '10.16.0',
     v8: '6.8.275.32-node.52',
     uv: '1.28.0',
     zlib: '1.2.11',
     brotli: '1.0.7',
     ares: '1.15.0',
     modules: '64',
     nghttp2: '1.34.0',
     napi: '4',
     openssl: '1.1.1b',
     icu: '64.2',
     unicode: '12.1',
     cldr: '35.1',
     tz: '2019a' },
  arch: 'x64',
  platform: 'win32',
  release:
   { name: 'node',
     lts: 'Dubnium',
     sourceUrl:
      'https://nodejs.org/download/release/v10.16.0/node-v10.16.0.tar.gz',
     headersUrl:
      'https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz',
     libUrl:
      'https://nodejs.org/download/release/v10.16.0/win-x64/node.lib' },
  argv:
   [ 'C:\\Program Files\\nodejs\\node.exe',
     'E:\\BaiduNetdiskDownload\\vue-imooc-ebook-chapter-master\\process.js' ],
  execArgv: [],
  env:
   { ALLUSERSPROFILE: 'C:\\ProgramData',
     APPDATA: 'C:\\Users\\hyx\\AppData\\Roaming',
     CommonProgramFiles: 'C:\\Program Files\\Common Files',
     'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
     CommonProgramW6432: 'C:\\Program Files\\Common Files',
     COMPUTERNAME: 'DESKTOP-6900FKS',
     ComSpec: 'C:\\WINDOWS\\system32\\cmd.exe',
     DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
     HOMEDRIVE: 'C:',
     HOMEPATH: '\\Users\\hyx',
     LOCALAPPDATA: 'C:\\Users\\hyx\\AppData\\Local',
     LOGONSERVER: '\\\\DESKTOP-6900FKS',
     NODE_ENV: 'production',
     NUMBER_OF_PROCESSORS: '4',
     NVM_HOME: 'F:\\nvm\\nvm',
     NVM_SYMLINK: 'C:\\Program Files\\nodejs',
     OneDrive: 'C:\\Users\\hyx\\OneDrive',
     OS: 'Windows_NT',
     Path:
      'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;F:\\Git\\cmd;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;F:\\nvm\\nvm;C:\\Program Files\\nodejs;;F:\\Microsoft VS Code\\bin;C:\\Users\\hyx\\AppData\\Roaming\\npm;C:\\Users\\hyx\\AppData\\Local\\Microsoft\\WindowsApps;F:\\nvm\\nvm;C:\\Program Files\\nodejs',
     PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
     PROCESSOR_ARCHITECTURE: 'AMD64',
     PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 60 Stepping 3, GenuineIntel',
     PROCESSOR_LEVEL: '6',
     PROCESSOR_REVISION: '3c03',
     ProgramData: 'C:\\ProgramData',
     ProgramFiles: 'C:\\Program Files',
     'ProgramFiles(x86)': 'C:\\Program Files (x86)',
     ProgramW6432: 'C:\\Program Files',
     PROMPT: '$P$G',
     PSModulePath: 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\',
     PUBLIC: 'C:\\Users\\Public',
     SESSIONNAME: 'Console',
     SystemDrive: 'C:',
     SystemRoot: 'C:\\WINDOWS',
     TEMP: 'C:\\Users\\hyx\\AppData\\Local\\Temp',
     TMP: 'C:\\Users\\hyx\\AppData\\Local\\Temp',
     USERDOMAIN: 'DESKTOP-6900FKS',
     USERDOMAIN_ROAMINGPROFILE: 'DESKTOP-6900FKS',
     USERNAME: 'hyx',
     USERPROFILE: 'C:\\Users\\hyx',
     windir: 'C:\\WINDOWS',
     TERM_PROGRAM: 'vscode',
     TERM_PROGRAM_VERSION: '1.41.1',
     LANG: 'zh_CN.UTF-8',
     COLORTERM: 'truecolor' },
  pid: 2588,
  features:
   { debug: false,
     uv: true,
     ipv6: true,
     tls_alpn: true,
     tls_sni: true,
     tls_ocsp: true,
     tls: true },
  ppid: 8924,
  execPath: 'C:\\Program Files\\nodejs\\node.exe',
  debugPort: 9229,
  _debugProcess: [Function: _debugProcess],
  _debugEnd: [Function: _debugEnd],
  _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
  _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
  abort: [Function: abort],
  chdir: [Function: chdir],
  umask: [Function: umask],
  _getActiveRequests: [Function: _getActiveRequests],
  _getActiveHandles: [Function: _getActiveHandles],
  _kill: [Function: _kill],
  cwd: [Function: cwd],
  dlopen: [Function: dlopen],
  reallyExit: [Function: reallyExit],
  uptime: [Function: uptime],
  _rawDebug: [Function],
  moduleLoadList:
   [ 'Internal Binding module_wrap',
     'Binding contextify',
     'Internal Binding worker',
     'NativeModule events',
     'NativeModule internal/async_hooks',
     'NativeModule internal/errors',
     'Binding uv',
     'Binding buffer',
     'Binding async_wrap',
     'Internal Binding async_wrap',
     'Binding config',
     'Binding icu',
     'NativeModule util',
     'NativeModule internal/util/inspect',
     'Binding util',
     'NativeModule internal/util',
     'Binding constants',
     'Internal Binding types',
     'NativeModule internal/util/types',
     'NativeModule internal/validators',
     'NativeModule internal/encoding',
     'Internal Binding icu',
     'NativeModule buffer',
     'NativeModule internal/buffer',
     'NativeModule internal/process/per_thread',
     'NativeModule internal/process/main_thread_only',
     'NativeModule internal/process/stdio',
     'NativeModule assert',
     'NativeModule internal/assert',
     'NativeModule fs',
     'NativeModule path',
     'NativeModule internal/constants',
     'Binding fs',
     'NativeModule internal/fs/streams',
     'NativeModule internal/fs/utils',
     'NativeModule stream',
     'NativeModule internal/streams/pipeline',
     'NativeModule internal/streams/end-of-stream',
     'NativeModule internal/streams/legacy',
     'NativeModule _stream_readable',
     'NativeModule internal/streams/buffer_list',
     'NativeModule internal/streams/destroy',
     'NativeModule internal/streams/state',
     'NativeModule _stream_writable',
     'NativeModule _stream_duplex',
     'NativeModule _stream_transform',
     'NativeModule _stream_passthrough',
     'NativeModule internal/url',
     'NativeModule internal/querystring',
     'Binding url',
     'NativeModule internal/process/warning',
     'NativeModule internal/process/next_tick',
     'NativeModule internal/process/promises',
     'Internal Binding util',
     'NativeModule internal/fixed_queue',
     'Binding performance',
     'Binding trace_events',
     'NativeModule internal/inspector_async_hook',
     'Binding inspector',
     'NativeModule internal/options',
     'Internal Binding options',
     'NativeModule timers',
     'Binding timer_wrap',
     'NativeModule internal/linkedlist',
     'NativeModule internal/timers',
     'NativeModule console',
     'Binding tty_wrap',
     'Internal Binding tty_wrap',
     'NativeModule tty',
     'NativeModule net',
     'NativeModule internal/net',
     'Binding stream_wrap',
     'Binding tcp_wrap',
     'Binding pipe_wrap',
     'NativeModule internal/stream_base_commons',
     'Internal Binding stream_wrap',
     'Internal Binding uv',
     'NativeModule internal/tty',
     'Binding signal_wrap',
     'NativeModule internal/modules/cjs/loader',
     'NativeModule vm',
     'NativeModule internal/modules/cjs/helpers',
     'NativeModule url',
     'NativeModule internal/safe_globals',
     'Internal Binding contextify',
     'NativeModule os',
     'Binding os' ],
  binding: [Function: binding],
  _linkedBinding: [Function: _linkedBinding],
  _events:
   [Object: null prototype] {
     newListener: [Function],
     removeListener: [Function],
     warning: [Function],
     SIGWINCH: [ [Function], [Function] ] },
  _eventsCount: 4,
  _maxListeners: undefined,
  _fatalException: [Function],
  domain: null,
  _exiting: false,
  assert: [Function: deprecated],
  config:
   { target_defaults:
      { cflags: [],
        default_configuration: 'Release',
        defines: [],
        include_dirs: [],
        libraries: [] },
     variables:
      { asan: 0,
        build_v8_with_gn: false,
        coverage: false,
        debug_nghttp2: false,
        enable_lto: false,
        enable_pgo_generate: false,
        enable_pgo_use: false,
        force_dynamic_crt: 0,
        host_arch: 'x64',
        icu_data_in: '..\\..\\deps/icu-small\\source/data/in\\icudt64l.dat',
        icu_endianness: 'l',
        icu_gyp_path: 'tools/icu/icu-generic.gyp',
        icu_locales: 'en,root',
        icu_path: 'deps/icu-small',
        icu_small: true,
        icu_ver_major: '64',
        nasm_version: '2.14',
        node_byteorder: 'little',
        node_debug_lib: false,
        node_enable_d8: false,
        node_enable_v8_vtunejit: false,
        node_install_npm: true,
        node_module_version: 64,
        node_no_browser_globals: false,
        node_prefix: '/usr/local',
        node_release_urlbase: 'https://nodejs.org/download/release/',
        node_shared: false,
        node_shared_cares: false,
        node_shared_http_parser: false,
        node_shared_libuv: false,
        node_shared_nghttp2: false,
        node_shared_openssl: false,
        node_shared_zlib: false,
        node_tag: '',
        node_target_type: 'executable',
        node_use_bundled_v8: true,
        node_use_dtrace: false,
        node_use_etw: true,
        node_use_large_pages: false,
        node_use_openssl: true,
        node_use_pch: false,
        node_use_perfctr: true,
        node_use_v8_platform: true,
        node_with_ltcg: true,
        node_without_node_options: false,
        openssl_fips: '',
        openssl_no_asm: 0,
        shlib_suffix: 'so.64',
        target_arch: 'x64',
        v8_enable_gdbjit: 0,
        v8_enable_i18n_support: 1,
        v8_enable_inspector: 1,
        v8_no_strict_aliasing: 1,
        v8_optimized_debug: 0,
        v8_promise_internal_field_count: 1,
        v8_random_seed: 0,
        v8_trace_maps: 0,
        v8_typed_array_max_size_in_heap: 0,
        v8_use_snapshot: true,
        want_separate_host_toolset: 0 } },
  setUncaughtExceptionCaptureCallback: [Function],
  hasUncaughtExceptionCaptureCallback: [Function],
  emitWarning: [Function],
  nextTick: [Function: nextTick],
  _tickCallback: [Function: _tickCallback],
  stdout: [Getter],
  stderr: [Getter],
  stdin: [Getter],
  openStdin: [Function],
  hrtime: { [Function: hrtime] bigint: [Function] },
  cpuUsage: [Function: cpuUsage],
  memoryUsage: [Function: memoryUsage],
  exit: [Function],
  kill: [Function],
  argv0: 'node',
  allowedNodeEnvironmentFlags: [Getter/Setter],
  mainModule:
   Module {
     id: '.',
     exports: {},
     parent: null,
     filename:
      'E:\\BaiduNetdiskDownload\\vue-imooc-ebook-chapter-master\\process.js',
     loaded: false,
     children: [],
     paths:
      [ 'E:\\BaiduNetdiskDownload\\vue-imooc-ebook-chapter-master\\node_modules',
        'E:\\BaiduNetdiskDownload\\node_modules',
        'E:\\node_modules' ] } }

 

你可能感兴趣的:(JavaScript,前端开发,Webpack,Webpack,前端开发)