Last active
February 27, 2019 15:32
-
-
Save XiongJingzhi/b298e15ecb08aebf1639bfc81ee2aa7f to your computer and use it in GitHub Desktop.
前端工具链配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn global add gulp-cli | |
"devDependencies": { | |
"@babel/core": "^7.3.4", | |
"@babel/preset-env": "^7.3.4", | |
"browser-sync": "^2.26.3", | |
"del": "^3.0.0", | |
"gulp": "^4.0.0", | |
"gulp-autoprefixer": "^6.0.0", | |
"gulp-babel": "^8.0.0", | |
"gulp-clean-css": "^4.0.0", | |
"gulp-concat": "^2.6.1", | |
"gulp-cssnano": "^2.1.3", | |
"gulp-file-include": "^2.0.1", | |
"gulp-filter": "^5.1.0", | |
"gulp-font-spider": "^0.3.6", | |
"gulp-htmlmin": "^5.0.1", | |
"gulp-imagemin": "^5.0.3", | |
"gulp-notify": "^3.2.0", | |
"gulp-rename": "^1.4.0", | |
"gulp-replace": "^1.0.0", | |
"gulp-rev-append": "^0.1.8", | |
"gulp-sass": "^4.0.2", | |
"gulp-typescript": "^5.0.0", | |
"gulp-uglify": "^3.0.1", | |
"typescript": "^3.3.3333" | |
} | |
// 根据gulpfile 增删查改 | |
const gulp = require('gulp') | |
const sass = require('gulp-sass') | |
const babel = require('gulp-babel') | |
const concat = require('gulp-concat') | |
const uglify = require('gulp-uglify') | |
const rename = require('gulp-rename') | |
const cleanCSS = require('gulp-clean-css') | |
const autoprefixer = require('gulp-autoprefixer') | |
const del = require('del') | |
const htmlmin = require('gulp-htmlmin') | |
const fileinclude = require('gulp-file-include') // 可以 include html 文件 | |
const imagemin = require('gulp-imagemin') // 图片优化 | |
const browserSync = require('browser-sync') // 保存自动刷新 | |
const server = browserSync.create() | |
const paths = { | |
styles: { | |
src: 'src/styles/**/*.{css,sass,scss}', | |
dest: 'assets/styles/' | |
}, | |
scripts: { | |
src: 'src/scripts/**/*.js', | |
dest: 'assets/scripts/' | |
}, | |
html: { | |
src: 'src/**/*.html', | |
dest: 'assets/' | |
}, | |
images: { | |
src: 'src/images/**/*.{jpg,jpeg,png,gif}', | |
dest: 'assets/images' | |
} | |
} | |
/* Not all tasks need to use streams, a gulpfile is just another node program | |
* and you can use all packages available on npm, but it must return either a | |
* Promise, a Stream or take a callback and call it | |
*/ | |
function clean() { | |
// You can use multiple globbing patterns as you would with `gulp.src`, | |
// for example if you are using del 2.0 or above, return its promise | |
return del(['assets']) | |
} | |
/* | |
* Define our tasks using plain functions | |
*/ | |
function styles() { | |
return gulp.src(paths.styles.src) | |
.pipe(sass({ | |
outputStyle: 'expanded' | |
})) | |
.pipe(autoprefixer('last 6 version')) | |
.pipe(gulp.dest('assets/sass')) | |
.pipe(cleanCSS()) | |
// pass in options to the stream | |
.pipe(rename({ | |
suffix: '.min' | |
})) | |
.pipe(gulp.dest(paths.styles.dest)) | |
.pipe(concat('main.min.css')) | |
.pipe(gulp.dest(paths.styles.dest)) | |
} | |
function scripts() { | |
return gulp.src(paths.scripts.src, { sourcemaps: true }) | |
.pipe(babel()) | |
.pipe(uglify()) | |
.pipe(concat('main.min.js')) | |
.pipe(gulp.dest(paths.scripts.dest)) | |
} | |
function html() { | |
return gulp.src(paths.html.src) | |
.pipe(fileinclude({ | |
prefix: '@@', // 变量前缀 @@include | |
basepath: './src/_include', // 引用文件路径 | |
indent: true// 保留文件的缩进 | |
})) | |
.pipe(htmlmin({ collapseWhitespace: true })) // 压缩html | |
.pipe(gulp.dest(paths.html.dest)) | |
} | |
function images() { | |
return gulp.src(paths.images.src) | |
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true, multipass: true })) | |
// 取值范围:0-7(优化等级),是否无损压缩jpg图片,是否隔行扫描gif进行渲染,是否多次优化svg直到完全优化 | |
.pipe(gulp.dest(paths.images.dest)) | |
} | |
function serve(done) { | |
server.init({ | |
server: { | |
baseDir: './assets' | |
}, | |
open: 'external' | |
}) | |
done() | |
} | |
function reload(done) { | |
server.reload() | |
done() | |
} | |
function watch() { | |
gulp.watch(paths.scripts.src, gulp.series(scripts, reload)) | |
gulp.watch(paths.styles.src, gulp.series(styles, reload)) | |
gulp.watch(paths.html.src, gulp.series(html, reload)) | |
gulp.watch(paths.images.src, gulp.series(images, reload)) | |
} | |
/* | |
* Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel` | |
*/ | |
const build = gulp.series(clean, gulp.parallel(styles, scripts, html, images), serve, watch) | |
/* | |
* You can use CommonJS `exports` module notation to declare tasks | |
*/ | |
exports.clean = clean | |
exports.styles = styles | |
exports.scripts = scripts | |
exports.watch = watch | |
exports.build = build | |
/* | |
* Define default task that can be called by just running `gulp` from cli | |
*/ | |
exports.default = build | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
babel处理es系列向后兼容,当前版本7 | |
配置文件为.babelrc | |
有插件系统,可以兼容最新协议草案,比如 | |
"plugins": ["@babel/plugin-proposal-class-properties"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"eslintIntegration": true, | |
"singleQuote": true, | |
"semi": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
全部文件看做资源,进行打包 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vscode 插件安装 ESLint | |
yarn global add eslint 或者 yarn add eslint | |
生成.eslintrc.js配置,常用如下 | |
可有"parser": "babel-eslint"配合 | |
项目文件可有.eslintignore 如lib/*.js忽略检查 | |
ESLint插件有可以配置:常用的 | |
"eslint.validate": [], | |
"eslint.options": { | |
"configFile": "C:/Users/Administrator/.eslintrc.js" | |
}, | |
"eslint.run": "onSave", | |
"eslint.autoFixOnSave": true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
"env": { | |
"browser": true, | |
"commonjs": true, | |
"es6": true, | |
"node": true | |
}, | |
"extends": "eslint:recommended", | |
"parserOptions": { | |
"ecmaVersion": 2018, | |
"sourceType": "module" | |
}, | |
"rules": { | |
'accessor-pairs': 2, | |
'arrow-spacing': [2, { | |
'before': true, | |
'after': true | |
}], | |
'block-spacing': [2, 'always'], | |
'brace-style': [2, '1tbs', { | |
'allowSingleLine': true | |
}], | |
'camelcase': [0, { | |
'properties': 'always' | |
}], | |
'comma-dangle': [2, 'never'], | |
'comma-spacing': [2, { | |
'before': false, | |
'after': true | |
}], | |
'comma-style': [2, 'last'], | |
'constructor-super': 2, | |
'curly': [2, 'multi-line'], | |
'dot-location': [2, 'property'], | |
'eol-last': 2, | |
'eqeqeq': [2, 'allow-null'], | |
'generator-star-spacing': [2, { | |
'before': true, | |
'after': true | |
}], | |
'handle-callback-err': [2, '^(err|error)$'], | |
'indent': [2, 2, { | |
'SwitchCase': 1 | |
}], | |
'jsx-quotes': [2, 'prefer-single'], | |
'key-spacing': [2, { | |
'beforeColon': false, | |
'afterColon': true | |
}], | |
'keyword-spacing': [2, { | |
'before': true, | |
'after': true | |
}], | |
'new-cap': [2, { | |
'newIsCap': true, | |
'capIsNew': false | |
}], | |
'new-parens': 2, | |
'no-array-constructor': 2, | |
'no-caller': 2, | |
'no-console': 'off', | |
'no-class-assign': 2, | |
'no-cond-assign': 2, | |
'no-const-assign': 2, | |
'no-control-regex': 0, | |
'no-delete-var': 2, | |
'no-dupe-args': 2, | |
'no-dupe-class-members': 2, | |
'no-dupe-keys': 2, | |
'no-duplicate-case': 2, | |
'no-empty-character-class': 2, | |
'no-empty-pattern': 2, | |
'no-eval': 2, | |
'no-ex-assign': 2, | |
'no-extend-native': 2, | |
'no-extra-bind': 2, | |
'no-extra-boolean-cast': 2, | |
'no-extra-parens': [2, 'functions'], | |
'no-fallthrough': 2, | |
'no-floating-decimal': 2, | |
'no-func-assign': 2, | |
'no-implied-eval': 2, | |
'no-inner-declarations': [2, 'functions'], | |
'no-invalid-regexp': 2, | |
'no-irregular-whitespace': 2, | |
'no-iterator': 2, | |
'no-label-var': 2, | |
'no-labels': [2, { | |
'allowLoop': false, | |
'allowSwitch': false | |
}], | |
'no-lone-blocks': 2, | |
'no-mixed-spaces-and-tabs': 2, | |
'no-multi-spaces': 2, | |
'no-multi-str': 2, | |
'no-multiple-empty-lines': [2, { | |
'max': 1 | |
}], | |
'no-native-reassign': 2, | |
'no-negated-in-lhs': 2, | |
'no-new-object': 2, | |
'no-new-require': 2, | |
'no-new-symbol': 2, | |
'no-new-wrappers': 2, | |
'no-obj-calls': 2, | |
'no-octal': 2, | |
'no-octal-escape': 2, | |
'no-path-concat': 2, | |
'no-proto': 2, | |
'no-redeclare': 2, | |
'no-regex-spaces': 2, | |
'no-return-assign': [2, 'except-parens'], | |
'no-self-assign': 2, | |
'no-self-compare': 2, | |
'no-sequences': 2, | |
'no-shadow-restricted-names': 2, | |
'no-spaced-func': 2, | |
'no-sparse-arrays': 2, | |
'no-this-before-super': 2, | |
'no-throw-literal': 2, | |
'no-trailing-spaces': 2, | |
'no-undef': 2, | |
'no-undef-init': 2, | |
'no-unexpected-multiline': 2, | |
'no-unmodified-loop-condition': 2, | |
'no-unneeded-ternary': [2, { | |
'defaultAssignment': false | |
}], | |
'no-unreachable': 2, | |
'no-unsafe-finally': 2, | |
'no-unused-vars': [2, { | |
'vars': 'all', | |
'args': 'none' | |
}], | |
'no-useless-call': 2, | |
'no-useless-computed-key': 2, | |
'no-useless-constructor': 2, | |
'no-useless-escape': 0, | |
'no-whitespace-before-property': 2, | |
'no-with': 2, | |
'one-var': [2, { | |
'initialized': 'never' | |
}], | |
'operator-linebreak': [2, 'after', { | |
'overrides': { | |
'?': 'before', | |
':': 'before' | |
} | |
}], | |
'padded-blocks': [2, 'never'], | |
'quotes': [2, 'single', { | |
'avoidEscape': true, | |
'allowTemplateLiterals': true | |
}], | |
'semi': [2, 'never'], | |
'semi-spacing': [2, { | |
'before': false, | |
'after': true | |
}], | |
'space-before-blocks': [2, 'always'], | |
'space-before-function-paren': [2, 'never'], | |
'space-in-parens': [2, 'never'], | |
'space-infix-ops': 2, | |
'space-unary-ops': [2, { | |
'words': true, | |
'nonwords': false | |
}], | |
'spaced-comment': [2, 'always', { | |
'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','] | |
}], | |
'template-curly-spacing': [2, 'never'], | |
'use-isnan': 2, | |
'valid-typeof': 2, | |
'wrap-iife': [2, 'any'], | |
'yield-star-spacing': [2, 'both'], | |
'yoda': [2, 'never'], | |
'prefer-const': 2, | |
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, | |
'object-curly-spacing': [2, 'always', { | |
objectsInObjects: false | |
}], | |
'array-bracket-spacing': [2, 'never'] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment