-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
221 lines (208 loc) · 5.75 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Fetch required plugins
const { src, dest, series, parallel } = require("gulp"),
//imagemin = require("gulp-imagemin"),
sourcemaps = require("gulp-sourcemaps"),
concat = require("gulp-concat"),
sass = require("gulp-sass")(require("sass")),
autoprefixer = require("gulp-autoprefixer"),
cssnano = require("gulp-cssnano"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
notify = require("gulp-notify"),
cache = require("gulp-cache"),
clean = require("gulp-clean"),
babel = require("gulp-babel"),
rollup = require("gulp-rollup"),
babelRU = require("rollup-plugin-babel"),
infoPlugins = require("./build/gulp/Plugins");
//sass(require("sass"));
// All paths
const paths = {
// images: {
// src: ["./src/views/data/img/*"],
// dest: "./src/public/img/",
// },
styles: {
src: ["./src/views/data/scss/all.scss"],
dest: "./src/public/css/",
merge: "stylesheet",
},
scripts: {
src: ["./src/views/data/js/*.js"],
dest: "./src/public/js/",
merge: "javascript",
},
plugins: {
src: "/*",
dest: "./src/public/plugins/",
},
};
//Optimize images(.png, .jpeg, .gif, .svg)
// const imagesTask = () => {
// return gulp
// .src(paths.images.src)
// .pipe(
// cache(
// imagemin([
// imagemin.gifsicle({ interlaced: true }),
// imagemin.mozjpeg({ quality: 75, progressive: true }),
// imagemin.optipng({ optimizationLevel: 3 }),
// imagemin.svgo({
// plugins: [{ removeViewBox: true }, { cleanupIDs: false }],
// }),
// ])
// ).on("error", (error) => console.log(error))
// )
// .pipe(dest(paths.images.dest));
// //.pipe(notify({ message: "Images task complete" }));
// };
// Compile styles
/**
* To concat styles, add below code after sourcemaps is initialized
* .pipe(concat('{OutputFileName}.css'))
*
* Note - Not all plugins work with postcss, only the ones mentioned in their documentation
*/
const stylesTask = () => {
return src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(
sass({
style: "expanded",
}).on("error", sass.logError)
)
.pipe(concat(paths.styles.merge + ".css")) // So use gulp-rename to change the extension
.pipe(autoprefixer())
.pipe(dest(paths.styles.dest))
.pipe(cssnano())
.pipe(rename({ extname: ".min.css" }))
.pipe(sourcemaps.write("."))
.pipe(dest(paths.styles.dest));
//.pipe(notify({ message: "Styles task complete" }));
};
// Minify scripts
/**
* To concat scripts, add below code after sourcemaps is initialized
* .pipe(concat('{OutputFileName}.js'))
*/
const scriptsTask = () => {
const pkg = require("./package");
const year = new Date().getFullYear();
return (
src(paths.scripts.src)
.pipe(sourcemaps.init())
.pipe(
rollup({
// any option supported by Rollup can be set here.
input: "./src/views/data/js/AdminLTE.js",
output: {
format: "umd",
name: paths.scripts.merge,
banner: `/*!
* MD AKHI v${pkg.version} (${pkg.homepage})
* Copyright 2021-${year} ${pkg.authors[0].name} (${pkg.authors[0].url})
* Licensed ${pkg.license.type}(${pkg.license.url})
*/`,
jquery: "jQuery",
},
plugins: [
babelRU({
presets: ["@babel/preset-env"],
//exclude: "node_modules/**",
externalHelpers: true,
}),
],
})
)
// .pipe(
// babel({
// presets: ["@babel/preset-env"],
// })
// )
//.pipe(concat(paths.scripts.merge + ".js")) // So use gulp-rename to change the extension
.pipe(rename({ basename: paths.scripts.merge, extname: ".js" }))
.pipe(dest(paths.scripts.dest))
.pipe(uglify().on("error", (error) => console.log(error)))
.pipe(rename({ extname: ".min.js" }))
.pipe(sourcemaps.write("."))
.pipe(dest(paths.scripts.dest))
);
//.pipe(notify({ message: "Scripts task complete" }));
};
// copy plugins
const pluginsTask = () => {
return infoPlugins.forEach((module) => {
src(module.from + paths.plugins.src, { allowEmpty: true }).pipe(
dest(paths.plugins.dest + module.to)
);
//.pipe(notify({ message: "Plugins task complete" }));
});
};
// Clean
const cleanTask = () => {
return src("src/public", { allowEmpty: true, read: false }).pipe(clean());
//.pipe(notify({ message: "Clean task complete" }));
};
const developmentTask = () => {
return series(cleanTask, stylesTask, scriptsTask, pluginsTask);
};
// const productionTask = () => {
// return series(cleanTask, stylesTask, scriptsTask, pluginsTask, imagesTask);
// };
//if (process.env.NODE_ENV === "development") {
// Default task
exports.default = developmentTask();
// } else {
// // Default task
// exports.default = productionTask();
// }
// const webpack = require("webpack-stream");
// task("default", function () {
// return gulp
// .src("src/file.js")
// .pipe(
// webpack({
// // Any configuration options...
// })
// )
// .pipe(dest("public/"));
// });
// gulpfile.js
// Load plugins
// let minifycss = require("gulp-minify-css"),
// jshint = require("gulp-jshint");
// // Styles
// task("styles", function () {
// return gulp
// .src("src/styles/main.scss")
// .pipe(sass({ style: "expanded" }))
// .pipe(
// autoprefixer(
// "last 2 version",
// "safari 5",
// "ie 8",
// "ie 9",
// "opera 12.1",
// "ios 6",
// "android 4"
// )
// )
// .pipe(dest("dist/styles"))
// .pipe(rename({ suffix: ".min" }))
// .pipe(minifycss())
// .pipe(dest("dist/styles"))
// .pipe(notify({ message: "Styles task complete" }));
// });
// // Scripts
// task("scripts", function () {
// return gulp
// .src("src/scripts/**/*.js")
// .pipe(jshint(".jshintrc"))
// .pipe(jshint.reporter("default"))
// .pipe(concat("main.js"))
// .pipe(dest("dist/scripts"))
// .pipe(rename({ suffix: ".min" }))
// .pipe(uglify())
// .pipe(dest("dist/scripts"))
// .pipe(notify({ message: "Scripts task complete" }));
// });