forked from robyth/amazeui-touch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
151 lines (129 loc) · 3.5 KB
/
gulpfile.babel.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Amaze UI Touch Building Tasks
*
* @author Minwe <[email protected]>
*/
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from './webpack.config';
import webpackConfigDev from './webpack.docs.babel';
import pkg from './package.json';
const $ = gulpLoadPlugins();
const banner = `/** ${pkg.title} v${pkg.version} | by Amaze UI Team
* (c) ${$.util.date(Date.now(), 'UTC:yyyy')} AllMobilize, Inc., Licensed under ${pkg.license}
* ${$.util.date(Date.now(), 'isoDateTime')}
*/
`;
const paths = {
scss: 'scss/amazeui.touch.scss',
scssModules: 'scss/**/*.scss',
fonts: 'fonts/*',
jsEntry: 'js/index.js',
dist: 'dist',
docsDist: 'www',
};
const autoprefixerOptions = {
browsers: ['> 1%', 'last 2 versions', 'ie 10']
};
const replaceVersion = function() {
return $.replace('__VERSION__', pkg.version);
};
const addBanner = function() {
return $.header(banner);
};
gulp.task('clean', () => {
return del(['dist', 'www', 'lib']);
});
/**
* Build Amaze UI Touch
*/
gulp.task('build:clean', () => {
return del([paths.dist, 'lib']);
});
gulp.task('style:scss', () => {
return gulp.src(paths.scss)
// inject fonts path
.pipe($.replace(/\/\/ INJECT_SASS_VAR/g, ''))
.pipe($.sass({
outputStyle: 'expanded',
importer: require('node-sass-import-once'),
}).on('error', $.sass.logError))
.pipe($.autoprefixer(autoprefixerOptions))
.pipe(addBanner())
.pipe(gulp.dest(paths.dist))
.pipe($.csso())
.pipe(addBanner())
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('style:fonts', () => {
return gulp.src(paths.fonts)
.pipe(gulp.dest(paths.dist + '/fonts'));
});
gulp.task('style', ['style:scss', 'style:fonts']);
// transform ES6 & JSX
gulp.task('build:babel', () => {
return gulp.src('js/**/*')
.pipe(replaceVersion())
// .pipe($.replace(/(import '\.\.\/scss\/components)/g, '// $1'))
.pipe($.babel({
plugins: require('./scripts/babel-require-ignore'),
}))
.pipe(gulp.dest('lib'));
});
gulp.task('build:pack', () => {
return gulp.src(paths.jsEntry)
.pipe(webpackStream(webpackConfig))
.pipe(replaceVersion())
.pipe(addBanner())
.pipe($.rename('amazeui.touch.js'))
.pipe(gulp.dest(paths.dist))
.pipe($.uglify())
.pipe(addBanner())
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('build', (callback) => {
runSequence(
'build:clean',
['style', 'build:babel', 'build:pack',],
callback
);
});
gulp.task('watch', () => {
gulp.watch('js/**/*.js', ['build:babel']);
});
/**
* Dev server
*/
gulp.task('docs:clean', () => {
return del(paths.docsDist);
});
gulp.task('server', () => {
const bundler = webpack(webpackConfigDev);
const bs = browserSync.create();
bs.init({
logPrefix: 'AMT',
server: {
baseDir: [paths.docsDist],
middleware: [
webpackDevMiddleware(bundler, {
publicPath: '/', // webpackConfigDev.output.publicPath,
stats: {colors: true}
}),
webpackHotMiddleware(bundler)
]
},
});
});
gulp.task('docs', (callback) => {
runSequence('docs:clean', 'server', callback);
});
gulp.task('default', ['docs']);