-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
115 lines (103 loc) · 3.21 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
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
const yargs = require('yargs');
const path = require('path');
const gulp = require('gulp');
const gutil = require('gulp-util');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const clean = require('gulp-clean');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const Eyeglass = require('eyeglass');
const webpackConfig = require('./webpack.config.js');
const paths = {
root: __dirname,
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist'),
};
function sassify() {
const options = {
outputStyle: 'compressed',
// eyeglass options
eyeglass: {
root: paths.root,
assets: {
httpPrefix: 'assets',
relativeTo: '/marvel-styleguide',
sources: [{
directory: path.resolve(paths.src, 'assets'),
globOpts: {
pattern: 'images/**/*',
},
}],
},
},
};
const eyeglass = new Eyeglass(options, sass);
return sass(eyeglass.options).on('error', sass.logError);
}
gulp.task('clean', () => (
gulp.src('dist', { read: false })
.pipe(clean())
));
gulp.task('clean:css', () => (
gulp.src('dist/css', { read: false })
.pipe(clean())
));
gulp.task('clean:site', () => (
gulp.src('dist/site', { read: false })
.pipe(clean())
));
gulp.task('build:css', ['clean:css'], () => (
gulp.src('src/sass/all.scss')
.pipe(sassify())
.pipe(rename({
basename: 'styleguide',
}))
.pipe(gulp.dest('dist/css'))
));
gulp.task('build:site', ['clean:site'], done => {
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurenceOrderPlugin()
);
webpack(webpackConfig, (err, stats) => {
console.log(err, stats);
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({
colors: true,
}));
done();
});
});
gulp.task('build', ['build:css', 'build:site']);
gulp.task('watch:css', () => {
const sassGlob = path.join(paths.src, 'sass/**/*.scss');
return gulp.watch(sassGlob, ['build:css']);
});
gulp.task('watch:site', ['clean:site'], () => {
webpackConfig.watch = true;
webpack(webpackConfig, (err, stats) => {
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({
colors: true,
}));
});
});
gulp.task('default', ['clean', 'build:css', 'watch:css'], () => {
yargs.option('port', {
alias: 'p',
describe: 'port to run webpack-dev-server on',
default: 9000,
});
const port = yargs.argv.port;
const uri = `http://localhost:${port}/`;
webpackConfig.entry.unshift(
`webpack-dev-server/client?${uri}`,
'webpack/hot/dev-server'
);
const compiler = webpack(webpackConfig);
new WebpackDevServer(compiler, webpackConfig.devServer).listen(port, 'localhost', err => {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[webpack-dev-server]', uri);
});
});