-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
141 lines (122 loc) · 3.5 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
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
const gulp = require('gulp');
const fs = require("fs");
const rimraf = require("rimraf");
const ncp = require("ncp").ncp;
const less=require("gulp-less");
// if less 4.1.1 not supported npm i --save-dev [email protected]
const path=require('path');
const browserify = require("browserify");
const babelify=require("babelify");
const source = require('vinyl-source-stream');
/*
We will talk more about node.js fs-module and ncp+rimraf extension modules later on
but to make this work you will need to:
> npm i --save requirejs
> npm i --save-dev gulp
> npm i --save-dev rimraf
> npm i --save-dev ncp
> npm i --save-dev @babel/core
> npm i --save-dev @babel/preset-env
> npm i --save-dev @babel/preset-react
> npm i --save-dev babelify
> npm i --save-dev browserify
> npm i --save-dev vinyl-source-stream
Possibly also:
> npm i -g gulp-cli
*/
/*
add postinstall script to your package.json
"postinstall":"gulp copyLibs"
*/
const wwwroot="wwwroot";
const libDir=wwwroot+"/libs";
const libFiles = [
'jquery/dist/jquery.js',
'bootstrap',
'requirejs/require.js'
];
function copyLibs(cb){
rimraf(libDir,function(){
fs.mkdir(libDir,function(){
libFiles.forEach(function(f){
fs.stat('node_modules/'+f,function(err,stat){
if (err){
console.log("Cannot stat",f);
return;
}
else{
if (stat.isDirectory()){
ncp('node_modules/'+f,libDir+'/'+f,function(err){
if (err) console.log("Error with",f)
else console.log('Copied',f);
})
}
else{
gulp.src('node_modules/'+f).pipe(gulp.dest(libDir));
}
}
})
})
cb();
})
})
}
//gulp.task('less', function () {
// return gulp.src('./styles/**/*.less')
// .pipe(less({
// paths: [ path.join(__dirname, 'less', 'includes') ]
// }))
// .pipe(gulp.dest('./wwwroot/styles'));
//});
function lessCompile(){
return gulp.src('./styles/**/*.less')
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(gulp.dest('./wwwroot/styles'));
//cb();
}
function es6(){
let sourceFolder='./jsadv/';
let startFile="es6main";
let targetFolder='./jsadv';
let file=sourceFolder+startFile+'.js';
let bundle=startFile+".bundle.js";
return browserify({
entries: file,
extensions: ['.js'],
debug: true
})
.transform(babelify.configure({presets: ["@babel/env"]}))
.bundle()
.on("error",err => {
console.log("ERROR:",err.message);
console.log(err.codeFrame);
})
.pipe(source(bundle))
.pipe(gulp.dest(targetFolder));
}
function jsx(){
let sourceFolder='./react2/';
let startFile="app";
let targetFolder='./wwwroot/app';
let file=sourceFolder+startFile+'.jsx';
let bundle=startFile+".bundle.js";
return browserify({
entries: file,
extensions: ['.js','.jsx'],
debug: true
})
.transform(babelify.configure({presets: ["@babel/env","@babel/react"]}))
.bundle()
.on("error",err => {
console.log("ERROR:",err.message);
console.log(err.codeFrame);
})
.pipe(source(bundle))
.pipe(gulp.dest(targetFolder));
}
exports.copyLibs=copyLibs;
exports.es6=es6;
exports.jsx=jsx;
exports.less=lessCompile;