为了减少文件大小，Vue 精简独立版本已经删除了所有警告，但是当你使用 webpack 或 Browserify 等工具时，你需要一些额外的配置实现这点。
If you are using the full build, i.e. directly including Vue via a script tag without a build tool, make sure to use the minified version (
vue.min.js) for production. Both versions can be found in the Installation guide.
When using a build tool like webpack or Browserify, the production mode will be determined by
process.env.NODE_ENV inside Vue’s source code, and it will be in development mode by default. Both build tools provide ways to overwrite this variable to enable Vue’s production mode, and warnings will be stripped by minifiers during the build. All
vue-cli templates have these pre-configured for you, but it would be beneficial to know how it is done:
使用 webpack 的 DefinePlugin 来指定生产环境，以便在压缩时可以让 UglifyJS 自动删除代码块内的警告语句。例如配置：
使用一个全局 envify 转换你的 bundle 文件。这可以精简掉包含在 Vue 源码中所有环境变量条件相关代码块内的警告语句。例如：NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js
The easiest way to pre-compile templates is using Single-File Components - the associated build setups automatically performs pre-compilation for you, so the built code contains the already compiled render functions instead of raw template strings.
Refer to the respective build tool documentations to see how it’s done:
- webpack + vue-loader (the
vue-cliwebpack template has this pre-configured)
- Browserify + vueify
- Rollup + rollup-plugin-vue