fix(create-app): should set css preprocessor

This commit is contained in:
陈嘉涵 2020-01-18 08:07:38 +08:00
parent fa9a64b480
commit 3baca25725
6 changed files with 16 additions and 18 deletions

View File

@ -1,3 +0,0 @@
.test {
color: red;
}

View File

@ -18,7 +18,7 @@ export default {
}; };
</script> </script>
<style lang="less"> <style lang="<%= cssLang %>">
.demo-button { .demo-button {
min-width: 120px; min-width: 120px;
color: #fff; color: #fff;

View File

@ -1,5 +0,0 @@
@import "./var.less";
body {
color: @text-color;
}

View File

@ -1,2 +0,0 @@
@primary-color: #f44;
@text-color: #4a4a4a;

View File

@ -1,6 +1,9 @@
module.exports = { module.exports = {
name: '<%= name %>', name: '<%= name %>',
build: { build: {
css: {
preprocessor: '<%= preprocessor %>',
},
site: { site: {
publicPath: '/<%= name %>/' publicPath: '/<%= name %>/'
} }

View File

@ -17,6 +17,7 @@ const PROMPTS = [
export class VanGenerator extends Generator { export class VanGenerator extends Generator {
inputs = { inputs = {
name: '', name: '',
cssLang: '',
preprocessor: '' preprocessor: ''
}; };
@ -32,8 +33,12 @@ export class VanGenerator extends Generator {
} }
async prompting() { async prompting() {
return this.prompt(PROMPTS).then(inputs => { return this.prompt<Record<string, string>>(PROMPTS).then(inputs => {
this.inputs.preprocessor = inputs.preprocessor as string; const preprocessor = inputs.preprocessor.toLowerCase();
const cssLang = preprocessor === 'sass' ? 'scss' : preprocessor;
this.inputs.cssLang = cssLang;
this.inputs.preprocessor = preprocessor;
}); });
} }
@ -44,21 +49,21 @@ export class VanGenerator extends Generator {
this.fs.copy(join(TEMPLATES, from), this.destinationPath(to || from)); this.fs.copy(join(TEMPLATES, from), this.destinationPath(to || from));
}; };
const copyTpl = (name: string, target?: string) => { const copyTpl = (from: string, to?: string) => {
this.fs.copyTpl( this.fs.copyTpl(
join(TEMPLATES, name), join(TEMPLATES, from),
this.destinationPath(target || name), this.destinationPath(to || from),
this.inputs this.inputs
); );
}; };
copyTpl('package.json.tpl', 'package.json'); copyTpl('package.json.tpl', 'package.json');
copyTpl('vant.config.js'); copyTpl('vant.config.js');
copyTpl('src/**/*', 'src');
copyTpl('docs/**/*', 'docs');
copy('babel.config.js'); copy('babel.config.js');
copy('gitignore.tpl', '.gitignore'); copy('gitignore.tpl', '.gitignore');
copy('eslintignore.tpl', '.eslintignore'); copy('eslintignore.tpl', '.eslintignore');
copy('src/**/*', 'src');
copy('docs/**/*', 'docs');
} }
install() { install() {