Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple CLI for scaffolding Vue.js projects

License

NotificationsYou must be signed in to change notification settings

jrtkcoder/vue-cli

 
 

Repository files navigation

A simple CLI for scaffolding Vue.js projects.

Installation

Prerequisites:Node.js (>=4.x, 6.x preferred) andGit.

$ npm install -g vue-cli

Usage

$ vue init<template-name><project-name>

Example:

$ vue init webpack my-project

The above command pulls the template fromvuejs-templates/webpack, prompts for some information, and generates the project at./my-project/.

vue build

Use vue-cli as a zero-configuration development tool for your Vue apps and component, check out thedocs.

Official Templates

The purpose of official Vue project templates are to provide opinionated, battery-included development tooling setups so that users can get started with actual app code as fast as possible. However, these templates are un-opinionated in terms of how you structure your app code and what libraries you use in addition to Vue.js.

All official project templates are repos in thevuejs-templates organization. When a new template is added to the organization, you will be able to runvue init <template-name> <project-name> to use that template. You can also runvue list to see all available official templates.

Current available templates include:

  • webpack - A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.

  • webpack-simple - A simple Webpack + vue-loader setup for quick prototyping.

  • browserify - A full-featured Browserify + vueify setup with hot-reload, linting & unit testing.

  • browserify-simple - A simple Browserify + vueify setup for quick prototyping.

  • simple - The simplest possible Vue setup in a single HTML file

Custom Templates

It's unlikely to make everyone happy with the official templates. You can simply fork an official template and then use it viavue-cli with:

vue init username/repo my-project

Whereusername/repo is the GitHub repo shorthand for your fork.

The shorthand repo notation is passed todownload-git-repo so you can also use things likebitbucket:username/repo for a Bitbucket repo andusername/repo#branch for tags or branches.

If you would like to download from a private repository use the--clone flag and the cli will usegit clone so your SSH keys are used.

Local Templates

Instead of a GitHub repo, you can also use a template on your local file system:

vue init~/fs/path/to-custom-template my-project

Writing Custom Templates from Scratch

  • A template repomust have atemplate directory that holds the template files.

  • A template repomay have a metadata file for the template which can be either ameta.js ormeta.json file. It can contain the following fields:

    • prompts: used to collect user options data;

    • filters: used to conditional filter files to render.

    • completeMessage: the message to be displayed to the user when the template has been generated. You can include custom instruction here.

prompts

Theprompts field in the metadata file should be an object hash containing prompts for the user. For each entry, the key is the variable name and the value is anInquirer.js question object. Example:

{"prompts": {"name": {"type":"string","required":true,"message":"Project name"    }  }}

After all prompts are finished, all files insidetemplate will be rendered usingHandlebars, with the prompt results as the data.

Conditional Prompts

A prompt can be made conditional by adding awhen field, which should be a JavaScript expression evaluated with data collected from previous prompts. For example:

{"prompts": {"lint": {"type":"confirm","message":"Use a linter?"    },"lintConfig": {"when":"lint","type":"list","message":"Pick a lint config","choices": ["standard","airbnb","none"      ]    }  }}

The prompt forlintConfig will only be triggered when the user answered yes to thelint prompt.

Pre-registered Handlebars Helpers

Two commonly used Handlebars helpers,if_eq andunless_eq are pre-registered:

{{#if_eqlintConfig"airbnb"}};{{/if_eq}}
Custom Handlebars Helpers

You may want to register additional Handlebars helpers using thehelpers property in the metadata file. The object key is the helper name:

module.exports={helpers:{lowercase:str=>str.toLowerCase()}}

Upon registration, they can be used as follows:

{{lowercasename}}

File filters

Thefilters field in the metadata file should be an object hash containing file filtering rules. For each entry, the key is aminimatch glob pattern and the value is a JavaScript expression evaluated in the context of prompt answers data. Example:

{"filters": {"test/**/*":"needTests"  }}

Files undertest will only be generated if the user answered yes to the prompt forneedTests.

Note that thedot option for minimatch is set totrue so glob patterns would also match dotfiles by default.

Skip rendering

TheskipInterpolation field in the metadata file should be aminimatch glob pattern. The files matched should skip rendering. Example:

{"skipInterpolation":"src/**/*.vue"}

Additional data available in meta.{js,json}

  • destDirName - destination directory name
{"completeMessage":"To get started:\n\n  cd {{destDirName}}\n  npm install\n  npm run dev"}
  • inPlace - generating template into current directory
{"completeMessage":"{{#inPlace}}To get started:\n\n  npm install\n  npm run dev.{{else}}To get started:\n\n  cd {{destDirName}}\n  npm install\n  npm run dev.{{/inPlace}}"}

Installing a specific template version

vue-cli uses the tooldownload-git-repo to download the official templates used. Thedownload-git-repo tool allows you to indicate a specific branch for a given repository by providing the desired branch name after a pound sign (#).

The format needed for a specific official template is:

vue init '<template-name>#<branch-name>' <project-name>

Example:

Installing the1.0 branch of the webpack-simple vue template:

vue init 'webpack-simple#1.0' mynewproject

Note: The surrounding quotes are necessary on zsh shells because of the special meaning of the# character.

License

MIT

About

Simple CLI for scaffolding Vue.js projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript98.7%
  • Other1.3%

[8]ページ先頭

©2009-2025 Movatter.jp