Skip to content

Instantly share code, notes, and snippets.

@yangzj1992
Last active February 22, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangzj1992/97a4c31f5596d45eb0df3cc32d707e7b to your computer and use it in GitHub Desktop.
Save yangzj1992/97a4c31f5596d45eb0df3cc32d707e7b to your computer and use it in GitHub Desktop.
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const watch = require('gulp-watch');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const eslint = require('gulp-eslint');
const cleanCSS = require('gulp-clean-css')
const postcss = require('gulp-postcss');
const reporter = require('postcss-reporter');
const syntax_scss = require('postcss-scss');
const stylelint = require('stylelint');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const plumber = require('gulp-plumber'); // Prevent pipe breaking caused by errors from gulp plugins
const sourcemaps = require('gulp-sourcemaps');
const prefixer = require('gulp-autoprefixer');
const stylefmt = require('gulp-stylefmt'); // stylefmt is a tool that automatically formats stylesheets.
const lintconfig = require('./stylelint.js')
gulp.task('css', function () {
const processors = [
require('postcss-salad')({}),
]
return gulp.src('themes/TKL-REVISION/source/scss/*.scss')
.pipe(postcss(processors,{syntax: syntax_scss}))
.pipe(gulp.dest('themes/TKL-REVISION/source/css/post/'));
});
gulp.task('serve', function() {
browserSync.init({
proxy: "localhost:4000"
});
// 监听文件变化
gulp.watch(['themes/TKL-REVISION/source/scss/*.scss'], ['sass','scripts']);
gulp.watch(['themes/TKL-REVISION/source/js/scripts.js','themes/TKL-REVISION/source/js/plugins.min.js'], ['scripts']);
gulp.watch(['themes/TKL-REVISION/source/js/scripts.js','themes/TKL-REVISION/source/css/style.css','themes/TKL-REVISION/source/**/*.*']).on('change', browserSync.reload)
});
gulp.task('sass',function(){
var stream = gulp.src('themes/TKL-REVISION/source/scss/index.scss')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('themes/TKL-REVISION/source/css/'));
return stream;
});
gulp.task('scripts', ['sass'],function() {
gulp.src(['themes/TKL-REVISION/source/js/plugins.min.js','themes/TKL-REVISION/source/js/nicescroll.js','themes/TKL-REVISION/source/js/layer.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat('base.js'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('themes/TKL-REVISION/source/js/'));
gulp.src(['themes/TKL-REVISION/source/css/index.css'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(prefixer('last 2 versions'))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('themes/TKL-REVISION/source/css/'))
});
// 默认任务
gulp.task('default',['scripts','serve']);
// lint
gulp.task('stylefmt', function () {
return gulp.src('themes/TKL-REVISION/source/scss/style.scss')
.pipe(stylefmt())
.pipe(gulp.dest('dist'));
});
gulp.task('lint',function(){
gulp.src(['themes/TKL-REVISION/source/js/scripts.js'])
.pipe(eslint({
extends: 'standard',
rules: {
"semi": [2, "always"]
},
globals: [
'jQuery',
'$'
],
envs: [
'browser',
'jquery'
]
}))
// .pipe(eslint.formatEach('compact', process.stderr));
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task("scss-lint", function() {
// Stylelint config rules
const stylelintConfig = lintconfig;
var processors = [
stylelint(stylelintConfig),
reporter({
clearMessages: true,
throwError: true
})
];
return gulp.src(
['themes/TKL-REVISION/source/scss/style.scss']
)
.pipe(gpostcss(processors, {syntax: syntax_scss}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment