template里.eslintrc.js之类的文件无法复制到新项目
模板
实际生成的项目:
.XXX这类格式的文件都无法复制到新项目
14
收起
正在回答 回答被采纳积分+1
2回答
陈小明
2020-03-23 11:55:31
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积分~
来为老师/同学的回答评分吧
0 星