{"action":"opened","issue":{"url":"https://api.github.com/repos/cycold/cycold.github.io/issues/111","repository_url":"https://api.github.com/repos/cycold/cycold.github.io","labels_url":"https://api.github.com/repos/cycold/cycold.github.io/issues/111/labels{/name}","comments_url":"https://api.github.com/repos/cycold/cycold.github.io/issues/111/comments","events_url":"https://api.github.com/repos/cycold/cycold.github.io/issues/111/events","html_url":"https://github.com/cycold/cycold.github.io/issues/111","id":170836024,"number":111,"title":"webpack 中console.log(process) 是一个对象","user":{"login":"cycold","id":2446601,"avatar_url":"https://avatars.githubusercontent.com/u/2446601?v=3","gravatar_id":"","url":"https://api.github.com/users/cycold","html_url":"https://github.com/cycold","followers_url":"https://api.github.com/users/cycold/followers","following_url":"https://api.github.com/users/cycold/following{/other_user}","gists_url":"https://api.github.com/users/cycold/gists{/gist_id}","starred_url":"https://api.github.com/users/cycold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cycold/subscriptions","organizations_url":"https://api.github.com/users/cycold/orgs","repos_url":"https://api.github.com/users/cycold/repos","events_url":"https://api.github.com/users/cycold/events{/privacy}","received_events_url":"https://api.github.com/users/cycold/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-12T09:46:23Z","updated_at":"2016-08-12T09:46:23Z","closed_at":null,"body":"编译后代码\r\n当即使使用环境变量NODE_ENV=\"****\" 如果没有通过 webpack插件\r\n```\r\nwebpack.DefinePlugin({\r\n    'process.env': {\r\n      NODE_ENV: '\"production\"'\r\n    }\r\n  }),\r\n```\r\n定义.那么在浏览器中输入 console.log(process.env.NODE_ENV) 将是空的. \r\n\r\nwebpack在模块中定义process对象,只是为了避免process.env.NODE_ENV报错. \r\n真正需要注入`process.env`到模块中,必须使用DefinePlugin插件\r\n\r\n\r\n```js\r\n/* 1 */\r\n/***/ function(module, exports) {\r\n\r\n\t// shim for using process in browser\r\n\tvar process = module.exports = {};\r\n\r\n\t// cached from whatever global is present so that test runners that stub it\r\n\t// don't break things.  But we need to wrap it in a try catch in case it is\r\n\t// wrapped in strict mode code which doesn't define any globals.  It's inside a\r\n\t// function because try/catches deoptimize in certain engines.\r\n\r\n\tvar cachedSetTimeout;\r\n\tvar cachedClearTimeout;\r\n\r\n\t(function () {\r\n\t    try {\r\n\t        cachedSetTimeout = setTimeout;\r\n\t    } catch (e) {\r\n\t        cachedSetTimeout = function () {\r\n\t            throw new Error('setTimeout is not defined');\r\n\t        }\r\n\t    }\r\n\t    try {\r\n\t        cachedClearTimeout = clearTimeout;\r\n\t    } catch (e) {\r\n\t        cachedClearTimeout = function () {\r\n\t            throw new Error('clearTimeout is not defined');\r\n\t        }\r\n\t    }\r\n\t} ())\r\n\tfunction runTimeout(fun) {\r\n\t    if (cachedSetTimeout === setTimeout) {\r\n\t        //normal enviroments in sane situations\r\n\t        return setTimeout(fun, 0);\r\n\t    }\r\n\t    try {\r\n\t        // when when somebody has screwed with setTimeout but no I.E. maddness\r\n\t        return cachedSetTimeout(fun, 0);\r\n\t    } catch(e){\r\n\t        try {\r\n\t            // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\r\n\t            return cachedSetTimeout.call(null, fun, 0);\r\n\t        } catch(e){\r\n\t            // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\r\n\t            return cachedSetTimeout.call(this, fun, 0);\r\n\t        }\r\n\t    }\r\n\r\n\r\n\t}\r\n\tfunction runClearTimeout(marker) {\r\n\t    if (cachedClearTimeout === clearTimeout) {\r\n\t        //normal enviroments in sane situations\r\n\t        return clearTimeout(marker);\r\n\t    }\r\n\t    try {\r\n\t        // when when somebody has screwed with setTimeout but no I.E. maddness\r\n\t        return cachedClearTimeout(marker);\r\n\t    } catch (e){\r\n\t        try {\r\n\t            // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally\r\n\t            return cachedClearTimeout.call(null, marker);\r\n\t        } catch (e){\r\n\t            // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\r\n\t            // Some versions of I.E. have different rules for clearTimeout vs setTimeout\r\n\t            return cachedClearTimeout.call(this, marker);\r\n\t        }\r\n\t    }\r\n\r\n\r\n\r\n\t}\r\n\tvar queue = [];\r\n\tvar draining = false;\r\n\tvar currentQueue;\r\n\tvar queueIndex = -1;\r\n\r\n\tfunction cleanUpNextTick() {\r\n\t    if (!draining || !currentQueue) {\r\n\t        return;\r\n\t    }\r\n\t    draining = false;\r\n\t    if (currentQueue.length) {\r\n\t        queue = currentQueue.concat(queue);\r\n\t    } else {\r\n\t        queueIndex = -1;\r\n\t    }\r\n\t    if (queue.length) {\r\n\t        drainQueue();\r\n\t    }\r\n\t}\r\n\r\n\tfunction drainQueue() {\r\n\t    if (draining) {\r\n\t        return;\r\n\t    }\r\n\t    var timeout = runTimeout(cleanUpNextTick);\r\n\t    draining = true;\r\n\r\n\t    var len = queue.length;\r\n\t    while(len) {\r\n\t        currentQueue = queue;\r\n\t        queue = [];\r\n\t        while (++queueIndex < len) {\r\n\t            if (currentQueue) {\r\n\t                currentQueue[queueIndex].run();\r\n\t            }\r\n\t        }\r\n\t        queueIndex = -1;\r\n\t        len = queue.length;\r\n\t    }\r\n\t    currentQueue = null;\r\n\t    draining = false;\r\n\t    runClearTimeout(timeout);\r\n\t}\r\n\r\n\tprocess.nextTick = function (fun) {\r\n\t    var args = new Array(arguments.length - 1);\r\n\t    if (arguments.length > 1) {\r\n\t        for (var i = 1; i < arguments.length; i++) {\r\n\t            args[i - 1] = arguments[i];\r\n\t        }\r\n\t    }\r\n\t    queue.push(new Item(fun, args));\r\n\t    if (queue.length === 1 && !draining) {\r\n\t        runTimeout(drainQueue);\r\n\t    }\r\n\t};\r\n\r\n\t// v8 likes predictible objects\r\n\tfunction Item(fun, array) {\r\n\t    this.fun = fun;\r\n\t    this.array = array;\r\n\t}\r\n\tItem.prototype.run = function () {\r\n\t    this.fun.apply(null, this.array);\r\n\t};\r\n\tprocess.title = 'browser';\r\n\tprocess.browser = true;\r\n\tprocess.env = {};\r\n\tprocess.argv = [];\r\n\tprocess.version = ''; // empty string to avoid regexp issues\r\n\tprocess.versions = {};\r\n\r\n\tfunction noop() {}\r\n\r\n\tprocess.on = noop;\r\n\tprocess.addListener = noop;\r\n\tprocess.once = noop;\r\n\tprocess.off = noop;\r\n\tprocess.removeListener = noop;\r\n\tprocess.removeAllListeners = noop;\r\n\tprocess.emit = noop;\r\n\r\n\tprocess.binding = function (name) {\r\n\t    throw new Error('process.binding is not supported');\r\n\t};\r\n\r\n\tprocess.cwd = function () { return '/' };\r\n\tprocess.chdir = function (dir) {\r\n\t    throw new Error('process.chdir is not supported');\r\n\t};\r\n\tprocess.umask = function() { return 0; };\r\n\r\n\r\n/***/ },\r\n```\r\n"}}
{"actor":{"display_login":"cycold"}}