建项
vue create 项目名 如上图所示是vue3.0手动配置项,各配置项意义如下
- Please pick a preset(请选择配置模式):default(默认配置),Manually select features(手动选择);此处我选的手动选择
- Check the features needed for your project(选择项目默认加载的依赖报):此处上下键移动,空格选中,回车下一步
- Use history mode for router? (Requires proper server setup for index fallback in production) Yes(选择vue-router是否开启history模式,详情查看vue-router的两种模式)
- Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)(选择css语言支持模式例如css/less等)
- Pick a linter / formatter config(选择eslint语法检查方式):此处我选的Standard(标准)
- Pick additional lint features(选择校验规则生效时间,此处我选的是保存页面时校验)
- Where do you prefer placing config for Babel, ESLint, etc.?(选择babel,esLint,etc等规则保存的位置),此处我选的使用独立文件保存
- Save this as a preset for future projects? (此处表示是否重命名项目名)
配置vue.config.js
module.exports = {
publicPath: '解决打包后部分静态资源获取失败',
publicPath: './',
outputDir: '打包后文件的目录',
outputDir: 'D://wd_gzh',
assetsDir: 'outputDir中的文件归纳到一个指定文件中',
assetsDir: 'static',
indexPath: '打包后index.html所在的目录以及文件名',
indexPath: 'D://wd_gzh/index.html',
}
配置.eslint.js
rules: {
// allow async-await
'generator-star-spacing': 'off',//生成器函数*的前后空格
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',//禁止使用debugger
'space-before-function-paren': ['error', {
'anonymous': 'never',
'named': 'never',
'asyncArrow': 'always'
}],//函数定义时括号前面要不要有空格
'one-var': ['error', 'always'],//连续声明
'no-unused-expressions': 0,//禁止无用的表达式
'prefer-promise-reject-errors': 0 // 禁止promise -> reject 传参为非Error类型的数据报错
}