search

Home  >  Q&A  >  body text

javascript - Webpack version 2.0 or above declares a __STAGE__ variable, and an error will be reported when referenced elsewhere, but version 1.0 does not report an error. Solution

Code declaring __STAGE__ in webpack.dev.conf.js

new webpack.DefinePlugin({
   'process.env': config.dev.env,
   __STAGE__: "'dev'"
 }),

The code quoted in reqData.js is as follows

req: function (p) {
    const req_obj = getReqObj(p)
    if (__STAGE__ === 'dev') {
      // console.log(__STAGE__)
      req_obj.apiName = p.apiName
      return test(req_obj)
    }
    delete req_obj.apiName
    return $ajax(req_obj)
  },

The same code, why does our project code not report an error when npm run dev, and can print out this variable, but the project I wrote myself reports an error when sending a request with this configuration. Is it because of the version? The company uses version 1.0, and mine is version 2.0.

高洛峰高洛峰2831 days ago596

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:33:13

    Just re-run the command npm run dev. What a trap!

    reply
    0
  • Cancelreply