-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (63 loc) · 1.65 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict'
const gulp = require( 'gulp' )
const util = require( 'gulp-util' )
const concat = require( 'gulp-concat-util' )
//const server = require( 'gulp-connect' ).server
const webpack = require( 'webpack' )
const mocha = require( 'gulp-mocha' )
const pkg = require( './package.json' )
const banner = (
`/*!
* Hanio v${pkg.version}
* Chen Yijun (@ethantw) | MIT License
* https://css.hanzi.co/hanio
* https://github.com/ethantw/hanio
*/\n
` )
// Unified tasks
gulp.task( 'default', [ 'build' ])
gulp.task( 'build', [ 'index.js', 'test' ])
gulp.task( 'dev', [ 'default', 'watch' ])
//gulp.task( 'server', () => server({ port: 3333 }))
gulp.task( 'watch', () => {
gulp.watch( './src/**/*.js', [ 'build' ])
gulp.watch( './test/**/*.js', [ 'test' ])
})
gulp.task( 'test', [ 'index.js' ], () =>
gulp.src( './test/index.js', { read: false })
.pipe(mocha())
)
gulp.task( 'index.js', [ 'pack' ], () =>
gulp.src( './dist/hanio.js' )
.pipe(concat( 'hanio.js', {
process: src => ( banner + src )
.replace( /@VERSION/g, pkg.version )
}))
.pipe(gulp.dest( './dist' ))
)
gulp.task( 'pack', callback =>
webpack({
entry: './src/index.js',
output: {
path: './dist',
filename: 'hanio.js',
libraryTarget: 'umd',
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel',
}]
},
externals: [ /^[a-z\-0-9]+$/ ],
babel: {
loose: 'all',
},
devtool: '#source-map',
}, ( error, stat ) => {
if ( error ) throw new util.PluginError( 'webpack', error )
util.log( '[webpack]', stat.toString())
callback()
})
)