template里.eslintrc.js之类的文件无法复制到新项目
模板
实际生成的项目:
.XXX这类格式的文件都无法复制到新项目
14
收起
正在回答 回答被采纳积分+1
2回答
陈小明
2020-03-23 11:55:31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | module.exports = class extends Generator { prompting() { // Have Yeoman greet the user. this .log( yosay(`Welcome to the divine ${chalk.red( 'generator-charming-vue-temp' )} generator!`) ); const prompts = [{ type: 'input' , name: 'name' , message: '请输入项目名?' , default : 'charming-vue-temp' }, { type: 'input' , name: 'description' , message: '请输入项目描述?' , default : 'a simple description' }, { type: 'input' , name: 'author' , message: '请输入项目作者?' , default : '' } ]; return this .prompt(prompts).then(props => { // To access props later use this.props.someAnswer; this .props = props; }); } writing() { this .fs.copy( this .templatePath( '**' ), this .destinationPath( './' ) ); // 下面文件默认不能直接应用在新项目里,故指定复制一份 const specFileList = [ '.browserslistrc' , '.eslintrc.js' ] specFileList.forEach(file => { this .fs.copy( this .templatePath(file), this .destinationPath(file)); }) // 改写package.json this .initPackage(); } initPackage () { let pkg = this .fs.readJSON( this .templatePath( './package.json' ), {}); const { props } = this ; Object.assign(pkg, { name: props.name, description: props.description, author: props.author }); this .fs.extendJSON( this .destinationPath( './package.json' ), pkg); } }; |
自己改写了一下yeoman的index.js文件:
增加了三个问题,让用户输入项目名,项目描述,和作者,并更新到package.json
增加了对.xxx这类型的文件的支持(支持.eslintrc.js
)关闭了默认的自动安装依赖(国内安装依赖时间太长,不想让用户觉得是因为使用我的脚手架而导致时间长)
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧