Skip to content

Commit

Permalink
add gulp work flow
Browse files Browse the repository at this point in the history
  • Loading branch information
acgotaku committed Apr 29, 2019
1 parent 21b72bf commit 64ccecb
Show file tree
Hide file tree
Showing 9 changed files with 10,879 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "@babel/preset-env" ]
}
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "standard",
"plugins": ["standard"]
"env": {
"browser": true
}
}
6 changes: 6 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "stylelint-config-sass-guidelines",
"rules": {
"max-nesting-depth": 4
}
}
109 changes: 109 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import gulp from 'gulp'

import plumber from 'gulp-plumber'
import gulpIf from 'gulp-if'

import eslint from 'gulp-eslint'
import stylelint from 'gulp-stylelint'


import postcss from 'gulp-postcss'
import sass from 'gulp-sass'
import autoprefixer from 'autoprefixer'
import concat from 'gulp-concat'
import cleanCSS from 'gulp-clean-css'

import rollupEach from 'gulp-rollup-each'
import rollupBabel from 'rollup-plugin-babel'
import rollupResolve from 'rollup-plugin-node-resolve'
import rollupCommon from 'rollup-plugin-commonjs'
import uglify from 'gulp-uglify'

import del from 'del'

const paths = {
styles: {
src: 'src/css/**/*.scss',
dest: 'dist/css/'
},
scripts: {
src: 'src/js/**/*.js',
dest: 'dist/js/'
},
images: {
src: 'src/images/**/*',
dest: 'dist/images/'
}
}

const config = {
plumberConfig: {
errorHandler: function (err) {
console.log(err.toString())
this.emit('end')
}
},
env: {
dev: process.env.NODE_ENV === 'development',
prod: process.env.NODE_ENV === 'production'
}
}

export const clean = () => del([ 'dist' ])

export function styles() {
return gulp.src(paths.styles.src, { sourcemaps: config.env.dev })
.pipe(plumber(config.plumberConfig))
.pipe(stylelint({
reporters: [
{ formatter: 'string', console: true }
]
}))
.pipe(sass({
outputStyle: 'nested',
precision: 3,
includePaths: ['.']
}))
.pipe(postcss([
autoprefixer({
browsers: ['last 1 versions']
})
]))
.pipe(concat('style.css'))
.pipe(gulpIf(config.env.prod, cleanCSS()))
.pipe(gulp.dest(paths.styles.dest), { sourcemaps: config.env.dev })
}

export function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: config.env.dev })
.pipe(plumber(config.plumberConfig))
.pipe(eslint())
.pipe(eslint.format())
.pipe(rollupEach({
isCache: true,
plugins: [
rollupBabel({
presets: ['@babel/preset-env']
}),
rollupResolve({
browser: true
}),
rollupCommon()
]},
{
format: 'iife'
}
))
.pipe(gulpIf(config.env.prod, uglify()))
.pipe(gulp.dest(paths.scripts.dest), { sourcemaps: config.env.dev })
}

export function watch() {
gulp.watch(paths.scripts.src, scripts)
gulp.watch(paths.styles.src, styles)
}
export const build = gulp.parallel(styles, scripts)

export const serve = gulp.series(clean, build, watch)

export const publish = gulp.series(clean, build)
Loading

0 comments on commit 64ccecb

Please sign in to comment.