Why webpack generate unused code?

I use webpack to pack vue project. Webpack version is 1.13.1. After build, i find the chunk js include unused code like below

    if (false) {(function () {  module.hot.accept()
      var hotAPI = require("vue-hot-reload-api")
      hotAPI.install(require("vue"), false)
      if (!hotAPI.compatible) return
      var id = "./welcome.vue"
      if (!module.hot.data) {
        hotAPI.createRecord(id, module.exports)
      } else {
        hotAPI.update(id, module.exports, __vue_template__)
      }
    })()}

Who can tell me why?

Author: Fantashit

1 thought on “Why webpack generate unused code?

  1. It’s unused because you’re not using webpack-dev-server or webpack-dev-middleware with hot reloading enabled. If it was enabled, it’d become if (true) instead.

    If you’re not sure about what I mean, the point of it becoming obviously unused code is that the UglifyJsPlugin can completely delete the if when you are making a production build.

Comments are closed.