Last active
July 31, 2017 02:44
-
-
Save alex1504/91032eaedfe5a8c310fb2ac46f9559ab to your computer and use it in GitHub Desktop.
基于generator-webapp 3.0.0;修复无法输出js的问题;增加sprite生成;增加跨域代理
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
{ | |
"name": "zhangyudih5", | |
"private": true, | |
"dependencies": { | |
"swiper": "^3.4.2", | |
"vue": "^2.4.2", | |
"lib-flexible": "*", | |
"weui": "^1.1.2", | |
"axios": "^0.16.2" | |
}, | |
"devDependencies": { | |
"chai": "^4.1.0", | |
"mocha": "^3.4.2" | |
} | |
} |
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
// generated on 2017-07-21 using generator-webapp 3.0.0 | |
const gulp = require('gulp'); | |
const gulpLoadPlugins = require('gulp-load-plugins'); | |
const browserSync = require('browser-sync').create(); | |
const del = require('del'); | |
const wiredep = require('wiredep').stream; | |
const runSequence = require('run-sequence'); | |
const spritesmith = require('gulp.spritesmith'); | |
const buffer = require('vinyl-buffer'); | |
const merge = require('merge-stream'); | |
const proxy = require('http-proxy-middleware'); | |
const $ = gulpLoadPlugins(); | |
const reload = browserSync.reload; | |
let dev = true; | |
/** | |
* Configure proxy middleware | |
*/ | |
let exampleProxy = proxy('/users', { | |
target: 'http://jsonplaceholder.typicode.com', // 代理域名 | |
changeOrigin: true, // for vhosted sites, changes host header to match to target's host | |
logLevel: 'debug' | |
}) | |
gulp.task('sprite', function() { | |
// Generate our spritesheet | |
var spriteData = gulp.src('app/images/icon-?*.png').pipe(spritesmith({ | |
imgName: 'icon_sprite.png', | |
cssName: '_mixin.icon.scss', | |
cssVarMap: function(sprite) { | |
sprite.name = sprite.name.replace("icon-", ""); | |
}, | |
padding: 20, | |
imgPath: '../images/icon_sprite.png' | |
})); | |
// Pipe image stream through image optimizer and onto disk | |
var imgStream = spriteData.img | |
// DEV: We must buffer our stream into a Buffer for `imagemin` | |
.pipe(buffer()) | |
.pipe($.imagemin()) | |
.pipe(gulp.dest('app/images/')); | |
// Pipe CSS stream through CSS optimizer and onto disk | |
var cssStream = spriteData.css | |
.pipe(gulp.dest('app/styles/')); | |
// Return a merged stream to handle both `end` events | |
return merge(imgStream, cssStream); | |
}); | |
gulp.task('styles', () => { | |
return gulp.src('app/styles/*.scss') | |
.pipe($.plumber()) | |
.pipe($.if(dev, $.sourcemaps.init())) | |
.pipe($.sass.sync({ | |
outputStyle: 'expanded', | |
precision: 10, | |
includePaths: ['.'] | |
}).on('error', $.sass.logError)) | |
.pipe($.autoprefixer({ browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'] })) | |
.pipe($.if(dev, $.sourcemaps.write())) | |
.pipe(gulp.dest('.tmp/styles')) | |
.pipe(reload({ stream: true })); | |
}); | |
gulp.task('scripts', () => { | |
return gulp.src('app/scripts/**/*.js') | |
.pipe($.plumber()) | |
.pipe($.if(dev, $.sourcemaps.init())) | |
.pipe($.babel()) | |
.pipe($.if(dev, $.sourcemaps.write('.'))) | |
.pipe(gulp.dest('.tmp/scripts')) | |
.pipe(reload({ stream: true })); | |
}); | |
function lint(files) { | |
return gulp.src(files) | |
.pipe($.eslint({ fix: true })) | |
.pipe(reload({ stream: true, once: true })) | |
.pipe($.eslint.format()) | |
.pipe($.if(!browserSync.active, $.eslint.failAfterError())); | |
} | |
gulp.task('lint', () => { | |
return gulp.src('app/scripts/**/*.js') | |
.pipe(gulp.dest('app/scripts')); | |
}); | |
gulp.task('lint:test', () => { | |
return lint('test/spec/**/*.js') | |
.pipe(gulp.dest('test/spec')); | |
}); | |
gulp.task('html', ['styles', 'scripts'], () => { | |
return gulp.src('./app/*.html') | |
.pipe($.useref({ searchPath: ['.tmp', 'app', '.'] })) | |
.pipe($.if(/\.js$/, $.uglify())) | |
.pipe($.if(/\.css$/, $.cssnano({ safe: true, autoprefixer: false }))) | |
/* .pipe($.if(/\.html$/, $.htmlmin({ | |
collapseWhitespace: true, | |
minifyCSS: true, | |
minifyJS: { compress: { drop_console: true } }, | |
processConditionalComments: true, | |
removeComments: true, | |
removeEmptyAttributes: true, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true | |
}))) */ | |
.pipe(gulp.dest('dist')); | |
}); | |
gulp.task('images', () => { | |
return gulp.src('app/images/**/*') | |
.pipe($.cache($.imagemin())) | |
.pipe(gulp.dest('dist/images')); | |
}); | |
gulp.task('fonts', () => { | |
return gulp.src(require('main-bower-files')('**/*.{eot,svg,ttf,woff,woff2}', function(err) {}) | |
.concat('app/fonts/**/*')) | |
.pipe($.if(dev, gulp.dest('.tmp/fonts'), gulp.dest('dist/fonts'))); | |
}); | |
gulp.task('extras', () => { | |
return gulp.src([ | |
'app/*', | |
'!app/*.html' | |
], { | |
dot: true | |
}).pipe(gulp.dest('dist')); | |
}); | |
gulp.task('clean', del.bind(null, ['.tmp', 'dist'])); | |
gulp.task('serve', () => { | |
runSequence(['clean', 'wiredep'], ['styles', 'scripts', 'fonts'], () => { | |
browserSync.init({ | |
notify: false, | |
port: 9000, | |
server: { | |
baseDir: ['.tmp', 'app'], | |
routes: { | |
'/bower_components': 'bower_components' | |
}, | |
middleware: [exampleProxy] | |
}, | |
}); | |
gulp.watch([ | |
'app/*.html', | |
'app/images/**/*', | |
'.tmp/fonts/**/*' | |
]).on('change', reload); | |
gulp.watch('app/styles/**/*.scss', ['styles']); | |
gulp.watch('app/scripts/**/*.js', ['scripts']); | |
gulp.watch('app/fonts/**/*', ['fonts']); | |
gulp.watch('bower.json', ['wiredep', 'fonts']); | |
}); | |
}); | |
gulp.task('serve:dist', ['default'], () => { | |
browserSync.init({ | |
notify: false, | |
port: 9000, | |
server: { | |
baseDir: ['dist'] | |
} | |
}); | |
}); | |
gulp.task('serve:test', ['scripts'], () => { | |
browserSync.init({ | |
notify: false, | |
port: 9000, | |
ui: false, | |
server: { | |
baseDir: 'test', | |
routes: { | |
'/scripts': '.tmp/scripts', | |
'/bower_components': 'bower_components' | |
} | |
} | |
}); | |
gulp.watch('app/scripts/**/*.js', ['scripts']); | |
gulp.watch(['test/spec/**/*.js', 'test/index.html']).on('change', reload); | |
gulp.watch('test/spec/**/*.js', ['lint:test']); | |
}); | |
// inject bower components | |
gulp.task('wiredep', () => { | |
gulp.src('app/styles/*.scss') | |
.pipe($.filter(file => file.stat && file.stat.size)) | |
.pipe(wiredep({ | |
ignorePath: /^(\.\.\/)+/ | |
})) | |
.pipe(gulp.dest('app/styles')); | |
gulp.src('app/*.html') | |
.pipe(wiredep({ | |
ignorePath: /^(\.\.\/)*\.\./ | |
})) | |
.pipe(gulp.dest('app')); | |
}); | |
gulp.task('build', ['lint', 'html', 'images', 'fonts', 'extras'], () => { | |
return gulp.src('dist/**/*').pipe($.size({ title: 'build', gzip: true })); | |
}); | |
gulp.task('default', () => { | |
return new Promise(resolve => { | |
dev = false; | |
runSequence(['clean', 'wiredep'], 'build', resolve); | |
}); | |
}); |
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
{ | |
"private": true, | |
"engines": { | |
"node": ">=4" | |
}, | |
"devDependencies": { | |
"babel-core": "^6.4.0", | |
"babel-preset-es2015": "^6.3.13", | |
"babel-register": "^6.5.2", | |
"browser-sync": "^2.2.1", | |
"del": "^2.2.0", | |
"gulp": "^3.9.0", | |
"gulp-autoprefixer": "^3.0.1", | |
"gulp-babel": "^6.1.1", | |
"gulp-cache": "^0.4.2", | |
"gulp-cssnano": "^2.0.0", | |
"gulp-eslint": "^3.0.0", | |
"gulp-filter": "^4.0.0", | |
"gulp-htmlmin": "^3.0.0", | |
"gulp-if": "^2.0.2", | |
"gulp-imagemin": "^3.0.1", | |
"gulp-load-plugins": "^1.2.4", | |
"gulp-plumber": "^1.0.1", | |
"gulp-sass": "^2.0.0", | |
"gulp-size": "^2.1.0", | |
"gulp-sourcemaps": "^2.2.0", | |
"gulp-uglify": "^2.0.0", | |
"gulp-useref": "^3.0.0", | |
"gulp.spritesmith": "^6.5.1", | |
"http-proxy-middleware": "^0.17.4", | |
"main-bower-files": "^2.5.0", | |
"merge-stream": "^1.0.1", | |
"node-sass": "^4.5.3", | |
"run-sequence": "^1.2.2", | |
"vinyl-buffer": "^1.0.0", | |
"wiredep": "^4.0.0" | |
}, | |
"eslintConfig": { | |
"env": { | |
"es6": true, | |
"node": true, | |
"browser": true | |
}, | |
"rules": { | |
"quotes": [ | |
2, | |
"single" | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment