1 Star 0 Fork 0

mengyibo/pages-boilerplate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 4.07 KB
一键复制 编辑 原始数据 按行查看 历史
mengyb 提交于 2021-01-24 22:08 . feat: 一点点修改
// 实现这个项目的构建任务
const { src, dest, parallel,series,watch } = require('gulp')
const loadPlugins = require('gulp-load-plugins')
const del = require('del')
const browserSync = require('browser-sync')
const minimist = require('minimist')
const pkg = require('./package.json')
const plugins = loadPlugins()
const bs = browserSync.create()
const data = {
menus: [
{
name: 'Home',
icon: 'aperture',
link: 'index.html'
},
{
name: 'Features',
link: 'features.html'
},
{
name: 'About',
link: 'about.html'
},
{
name: 'Contact',
link: '#',
children: [
{
name: 'Twitter',
link: 'https://twitter.com/w_zce'
},
{
name: 'About',
link: 'https://weibo.com/zceme'
},
{
name: 'divider'
},
{
name: 'About',
link: 'https://github.com/zce'
}
]
}
],
pkg: require('./package.json'),
date: new Date()
}
const config{
'debug': process.env.NODE_ENV !== 'production'
}
const clean = () =>{
return del(['dist','temp'])
}
const styles = () =>{
return src('src/assets/styles/*.scss',{base:'src'})
.pipe(plugins.sass({outputStyle:'expanded'}))
.pipe(plugins.if(!config.debug, plugins.autoprefixer({ browsers: pkg.browserslist })))
.pipe(dest('temp'))
.pipe(bs.reload({stream:true}))
}
const script = () =>{
return src('src/assets/scripts/*.js',{base:'src'})
.pipe(plugins.babel({presets:['@babel/preset-env']}))
.pipe(dest('temp'))
.pipe(bs.reload({stream:true}))
}
const pages = () =>{
return src('src/**/*.html',{base:'src'})
.pipe(plugins.plumber())
.pipe(plugins.swig({ data,defaults: { cache: false }}))
.pipe(dest('temp'))
.pipe(bs.reload({stream:true}))
}
const image = () => {
return src('src/assets/images/**',{base:'src'})
.pipe(plugins.imagemin())
.pipe(dest('dist'))
}
const font = () => {
return src('src/assets/fonts/**',{base:'src'})
.pipe(plugins.imagemin())
.pipe(dest('dist'))
}
const extra = () =>{
return src('public/**',{base:'public'})
.pipe(dest('dist'))
}
const serve = () =>{
watch('src/assets/styles/*.scss',styles)
watch('src/assets/scripts/*.js',script)
watch('src/**/*.html',pages)
watch([
'src/assets/images/*',
'src/assets/fonts/**',
'public/**'
],bs.reload)
bs.init({
notify:false,
port: 2080,
files: 'dist/**',
server: {
baseDir: ['dist'],
// baseDir: ['dist'],
routes:{
'/node_modules': 'node_modules'
}
}
})
}
const useref = () =>{
return src('temp/**/*.html', {base: 'temp'})
.pipe(plugins.useref({searchPath: ['temp','.']}))
// html js css
.pipe(plugins.if(/\.js$/,plugins.uglify()))
.pipe(plugins.if(/\.css$/,plugins.cleanCss()))
.pipe(plugins.if(/\.html$/,plugins.htmlmin({
collapseWhitespace:true,
minifyCSS: true,
minifyJS: true
})))
.pipe(dest('dist'))
}
const argv = minimist(process.argv.slice(2))
const upload = () =>{
return src('**', { cwd: 'dist' })
.pipe(
plugins.ghPages({
branch: argv.branch === undefined ? 'gh-pages' : argv.branch
})
)
}
const lint = () => {
return src('src/assets/scripts/*.js', {base:'src'})
.pipe(plugins.eslint({
"rules":{
"arrow-parens": 0,
"arrow-spacing": 0,
"comma-spacing": 0,
"generator-star-spacing": 0,
"key-spacing": [0, { "beforeColon": false, "afterColon": true }],
},
"env": {
"browser": true,
"commonjs": true,
"es6": true
}
}))
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError())
}
const compile = parallel(styles,script,pages,)
const build = series(clean,parallel(series(compile,useref),image,font,extra))
const start = series(build,serve)
const deploy = series(build,upload)
module.exports = {
clean,build,start,serve,deploy,lint
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mybmmm/pages-boilerplate.git
[email protected]:mybmmm/pages-boilerplate.git
mybmmm
pages-boilerplate
pages-boilerplate
master

搜索帮助