Skip to content

Commit 1beb58d

Browse files
committed
Custom build
1 parent 515ff39 commit 1beb58d

File tree

3 files changed

+186
-4
lines changed

3 files changed

+186
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
node_modules
33
build
4+
custom
45
*.log
56

67
.versions

gulpfile.js

+111-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
styles: 'build/css/',
2323
scripts: 'build/js/'
2424
},
25+
custom: {
26+
root: 'custom/',
27+
styles: 'custom/css/',
28+
scripts: 'custom/js/'
29+
},
2530
dist: {
2631
root: 'dist/',
2732
styles: 'dist/css/',
@@ -114,7 +119,7 @@
114119
'src/js/wrap-end-umd.js',
115120
],
116121
Framework7Files : [
117-
'src/js/swiper-intro-f7.js',
122+
'src/js/swiper-intro-swiper.js',
118123
'src/js/core.js',
119124
'src/js/effects.js',
120125
'src/js/lazy-load.js',
@@ -130,6 +135,7 @@
130135
'src/js/swiper-proto.js',
131136
],
132137
pkg: require('./bower.json'),
138+
modules: require('./modules.json'),
133139
banner: [
134140
'/**',
135141
' * Swiper <%= pkg.version %>',
@@ -146,6 +152,24 @@
146152
' * Released on: <%= date.month %> <%= date.day %>, <%= date.year %>',
147153
' */',
148154
''].join('\n'),
155+
customBanner: [
156+
'/**',
157+
' * Swiper <%= pkg.version %> - Custom Build',
158+
' * <%= pkg.description %>',
159+
' * ',
160+
' * Included modules: <%= modulesList %>',
161+
' * ',
162+
' * <%= pkg.homepage %>',
163+
' * ',
164+
' * Copyright <%= date.year %>, <%= pkg.author %>',
165+
' * The iDangero.us',
166+
' * http://www.idangero.us/',
167+
' * ',
168+
' * Licensed under <%= pkg.license.join(" & ") %>',
169+
' * ',
170+
' * Released on: <%= date.month %> <%= date.day %>, <%= date.year %>',
171+
' */',
172+
''].join('\n'),
149173
date: {
150174
year: new Date().getFullYear(),
151175
month: ('January February March April May June July August September October November December').split(' ')[new Date().getMonth()],
@@ -159,7 +183,7 @@
159183
if (['wrap-start.js', 'wrap-start-umd.js', 'wrap-end.js', 'wrap-end-umd.js', 'amd.js'].indexOf(filename) !== -1) {
160184
addIndent = '';
161185
}
162-
if (filename === 'swiper-intro.js' || filename === 'swiper-intro-f7.js' || filename === 'swiper-outro.js' || filename === 'dom.js' || filename === 'get-dom-lib.js' || filename === 'get-jquery.js' || filename === 'dom-plugins.js' || filename === 'swiper-proto.js') addIndent = ' ';
186+
if (filename === 'swiper-intro.js' || filename === 'swiper-intro-swiper.js' || filename === 'swiper-outro.js' || filename === 'dom.js' || filename === 'get-dom-lib.js' || filename === 'get-jquery.js' || filename === 'dom-plugins.js' || filename === 'swiper-proto.js') addIndent = ' ';
163187
if (minusIndent) {
164188
addIndent = addIndent.substring(4);
165189
}
@@ -231,10 +255,10 @@
231255

232256
gulp.src([
233257
paths.source.styles + 'core.less',
234-
paths.source.styles + 'navigation-f7.less',
258+
paths.source.styles + 'navigation-swiper.less',
235259
paths.source.styles + 'effects.less',
236260
paths.source.styles + 'scrollbar.less',
237-
paths.source.styles + 'preloader-f7.less',
261+
paths.source.styles + 'preloader-swiper.less',
238262
])
239263
.pipe(concat(swiper.filename + '.framework7.less'))
240264
.pipe(header('/* === Swiper === */\n'))
@@ -292,6 +316,89 @@
292316
.pipe(gulp.dest(paths.dist.styles));
293317
});
294318

319+
/* =================================
320+
Custom Build
321+
================================= */
322+
gulp.task('custom', function () {
323+
var modules = process.argv.slice(3);
324+
modules = modules.toString();
325+
if (modules === '') {
326+
modules = [];
327+
}
328+
else {
329+
modules = modules.substring(1).replace(/ /g, '').replace(/,,/g, ',');
330+
modules = modules.split(',');
331+
}
332+
var modulesJs = [], modulesLess = [];
333+
var i, module;
334+
modulesJs.push.apply(modulesJs, swiper.modules.core_intro.js);
335+
modulesLess.push.apply(modulesLess, swiper.modules.core_intro.less);
336+
337+
for (i = 0; i < modules.length; i++) {
338+
module = swiper.modules[modules[i]];
339+
if (!(module)) continue;
340+
341+
if (module.dependencies && module.dependencies.length > 0) {
342+
modules.push.apply(modules, module.dependencies);
343+
}
344+
if (module.js.length > 0) {
345+
modulesJs.push.apply(modulesJs, module.js);
346+
}
347+
if (module.less && module.less.length > 0) {
348+
modulesLess.push.apply(modulesLess, module.less);
349+
}
350+
}
351+
modulesJs.push.apply(modulesJs, swiper.modules.core_outro.js);
352+
modulesLess.push.apply(modulesLess, swiper.modules.core_outro.less);
353+
354+
// Unique
355+
var customJsList = [];
356+
var customLessList = [];
357+
for (i = 0; i < modulesJs.length; i++) {
358+
if (customJsList.indexOf(modulesJs[i]) < 0) customJsList.push(modulesJs[i]);
359+
}
360+
for (i = 0; i < modulesLess.length; i++) {
361+
if (customLessList.indexOf(modulesLess[i]) < 0) customLessList.push(modulesLess[i]);
362+
}
363+
364+
// JS
365+
gulp.src(customJsList)
366+
.pipe(tap(function (file, t){
367+
addJSIndent (file, t);
368+
}))
369+
.pipe(concat(swiper.filename + '.custom.js'))
370+
.pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') } ))
371+
.pipe(jshint())
372+
.pipe(jshint.reporter(stylish))
373+
.pipe(gulp.dest(paths.custom.scripts))
374+
375+
.pipe(uglify())
376+
.pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') }))
377+
.pipe(rename(function(path) {
378+
path.basename = path.basename + '.min';
379+
}))
380+
.pipe(gulp.dest(paths.custom.scripts));
381+
382+
// CSSes
383+
gulp.src(customLessList)
384+
.pipe(concat(swiper.filename + '.custom.less'))
385+
.pipe(less({
386+
paths: [ path.join(__dirname, 'less', 'includes') ]
387+
}))
388+
.pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') } ))
389+
.pipe(gulp.dest(paths.custom.styles))
390+
391+
.pipe(cleanCSS({
392+
advanced: false,
393+
aggressiveMerging: false
394+
}))
395+
.pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') }))
396+
.pipe(rename(function(path) {
397+
path.basename = path.basename + '.min';
398+
}))
399+
.pipe(gulp.dest(paths.custom.styles));
400+
});
401+
295402
gulp.task('watch', function () {
296403
gulp.watch(paths.source.scripts, [ 'scripts' ]);
297404
gulp.watch(paths.source.styles + '*.less', [ 'styles' ]);

modules.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"core_intro": {
3+
"js": [
4+
"src/js/wrap-start.js",
5+
"src/js/swiper-intro.js",
6+
"src/js/core.js"
7+
],
8+
"less": [
9+
"src/less/mixins.less",
10+
"src/less/core.less",
11+
"src/less/navigation.less",
12+
"src/less/preloader.less"
13+
]
14+
},
15+
"core_outro": {
16+
"js": [
17+
"src/js/plugins.js",
18+
"src/js/emitter.js",
19+
"src/js/init.js",
20+
"src/js/swiper-outro.js",
21+
"src/js/swiper-proto.js",
22+
"src/js/dom.js",
23+
"src/js/get-dom-lib.js",
24+
"src/js/dom-plugins.js",
25+
"src/js/wrap-end.js",
26+
"src/js/amd.js"
27+
],
28+
"less": []
29+
},
30+
"effects": {
31+
"js": ["src/js/effects.js"],
32+
"less": ["src/less/effects.less"]
33+
},
34+
"lazy-load": {
35+
"js": ["src/js/lazy-load.js"],
36+
"less": []
37+
},
38+
"scrollbar": {
39+
"js": ["src/js/scrollbar.js"],
40+
"less": ["src/less/scrollbar.less"]
41+
},
42+
"controller": {
43+
"js": ["src/js/controller.js"],
44+
"less": []
45+
},
46+
"hashnav": {
47+
"js": ["src/js/controller.js"],
48+
"less": []
49+
},
50+
"history": {
51+
"js": ["src/js/history.js"],
52+
"less": []
53+
},
54+
"keyboard": {
55+
"js": ["src/js/keyboard.js"],
56+
"less": []
57+
},
58+
"mousewheel": {
59+
"js": ["src/js/mousewheel.js"],
60+
"less": []
61+
},
62+
"parallax": {
63+
"js": ["src/js/parallax.js"],
64+
"less": []
65+
},
66+
"zoom": {
67+
"js": ["src/js/zoom.js"],
68+
"less": ["src/less/zoom.less"]
69+
},
70+
"a11y": {
71+
"js": ["src/js/a11y.js"],
72+
"less": []
73+
}
74+
}

0 commit comments

Comments
 (0)