平时工作中会写一些多页面应用,因为习惯了react的开发模式,故此写了一个简单的配置,跟大家一起分享。如果你也喜欢,对你的开发有所帮助,希望给点鼓励(start)
github地址:https://github.com/ivan-GM/Gm-cli
项目目录介绍:
打包后文件目录:
打包成cli如果你厌烦了新项目的复制、粘贴,也可以构建成cli
1,首先创建个文件夹,npm init初始化项目;
2, 创建bin目录,touch index.js 编写配置文件;
const commander = require('commander'); const inquirer = require('inquirer'); const download = require('download-git-repo') const ora = require('ora'); const questions = [ { type: 'input', name: 'projectName', message: 'project name:', filter: function (val) { return val; } } ] commander .option('init', 'create project') .version('1.0', '-v, --version') commander .command('init') .description('') .action(() => { inquirer.prompt(questions).then(answers => { const { projectName } = answers; const spinner = ora('Loading unicorns').start(); spinner.color = 'green'; spinner.text = 'downloading template...'; download('direct:https://github.com/ivan-GM/live', projectName, { clone: true }, (err) => { if (err) { console.log(err) } else { spinner.stop() console.log('sucess') } }) }) }); commander.parse(process.argv);
3,添加命令:打开package.json
"bin": { "my-cli": "./bin/index.js" },
4,发布npm
*上面代码只是对打包成cli进行了简单的说明,如果感兴趣了,可以深入研究