在用 Vue.js 构建大型应用时推荐使用 NPM 安装,NPM 能很好地和诸如 Webpack 或 Browserify 模块打包器配合使用。Vue.js 也提供配套工具来开发单文件组件。
# 最新稳定版 $ npm install vueVue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。该工具提供开箱即用的构建工具配置,带来现代化的前端开发流程。只需几分钟即可创建并启动一个带热重载、保存时静态检查以及可用于生产环境的构建配置的项目:
# 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack my-project # 安装依赖,走你 ? Project name (my-project) //请输入项目名称,回车默认 ? Project description (A Vue.js project) //请输入项目描述,回车默认 ? Author xsl <398818817@qq.com> //请输入作者名,回车默认 ? Vue build //请选择构建模式,请直接回车选择第一条 > Runtime + Compiler: recommended for most users Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere ? Install vue-router? Yes //是否安装vue-router,回车 ? Use ESLint to lint your code? Yes //是否安装ESLint代码检查器,回车 //个人比较偏爱airbnb的编码规范,此处选择第二项 Standard (https://github.com/feross/standard) >AirBNB (https://github.com/airbnb/javascript) none (configure it yourself) ? Setup unit tests with Karma + Mocha? Yes //单元测试,请按需选择 ? Setup e2e tests with Nightwatch? Yes //端到端测试,请按需选择 $ cd my-project $ npm install $ npm run dev 安装完成!可以开搞了