-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildToProduction.js
87 lines (81 loc) · 2.4 KB
/
BuildToProduction.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
const {src, dest, watch} = require('gulp');
const path = require('../projectConfig.json').path;
const sassGlob = require('gulp-sass-glob');
const sass = require('gulp-sass')(require('sass'));
const pug = require('gulp-pug');
const webp = require('gulp-webp');
const del = require('del');
const autoprefixer = require('gulp-autoprefixer');
const webpack = require('webpack');
const rename = require('gulp-rename');
const minify = require('gulp-minify');
const webpackStream = require("webpack-stream");
function buildPug (cb) {
return src(path.srcPath + '/pages/**/*.pug')
.pipe(
pug({
pretty:true,
data: require('../../charity/src/base/data/data.json')
})
)
.pipe(rename({
dirname:"",
}))
.pipe(dest(path.buildPath));
};
function buildCSS (){
return src(path.srcPath + '/styles/*.scss')
.pipe(sassGlob())
.pipe(sass({
outputStyle:'compressed',
}).on('error', sass.logError))
.pipe(autoprefixer({
cascade: false,
}))
.pipe(dest(path.buildPath + '/styles'));
}
function transformPicture() {
return src(path.srcPath +'/**/*.{png,jpeg}')
.pipe(webp({
method: 2,
}))
.pipe(rename(function (path){
// path.dirname = path.dirname.split("\\").filter(el=> el != 'images').join('\\')
path.dirname = ''
}))
.pipe(dest(path.buildPath+'/images'))
}
function copyOtherImg(){
return src(path.srcPath +'/**/*.{png,jpeg}')
.pipe(rename(function (path){
// path.dirname = path.dirname.split("\\").filter(el=> el != 'images').join('\\')
path.dirname = ''
}))
.pipe(dest(path.buildPath+'/images'))
}
function buildJS() {
return src('../src/pages/**/*.js')
.pipe(webpackStream(
require('../webpack.config.build.js')
))
.on('error', function (err) {
console.error('WEBPACK ERROR', err);
this.emit('end'); // Don't stop the rest of the task
})
.pipe(minify({
ext:{
min:'.js'
},
noSource: true
}))
.pipe(dest(path.buildPath))
}
exports.default = async (cb) =>{
await del(path.buildPath,{force:true});
buildPug();
buildCSS();
buildJS();
transformPicture();
copyOtherImg();
cb();
}