how to detect when browserify is being run?

后端 未结 3 1657
离开以前
离开以前 2021-02-02 12:53

I have a library that I want to use in both client side and server side. However, because request is not compatible with browserify, when compiling using browserify

3条回答
  •  伪装坚强ぢ
    2021-02-02 13:09

    I found the answer:

    if (typeof window === 'undefined') {
      var request = require('request');
    } else {
      var request = require('browser-request');
    }
    

    Superagent is also looking like a very good alternative!

提交回复
热议问题