-
Notifications
You must be signed in to change notification settings - Fork 1
/
gruntfile.js
82 lines (78 loc) · 3.07 KB
/
gruntfile.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
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
dom_munger: {
build: {
options: {
/*prefix: {
selector: 'link',
attribute: 'href',
value: 'project-name/'
},*/
remove: '[group="appended"]',
append: [
{
selector: 'body',
html: '<script class="loading" group="appended" type="text/javascript" src="./indexAnimationLoading.js"></script>'
},
{
selector: 'body',
html: '<script class="loading" group="appended" type="text/javascript" src="./indexAsynloading.js"></script>'
},
{
selector: 'body',
html: '<script class="loadScriptStyle" group="appended" type="text/javascript"></script>'
}
],
callback: function ($, file) {
//获取编译后的脚本,改为惰性加载
const src = [];
$('body')
.find('script[group!="appended"]')
.each(function () {
src.push($(this)
.attr('src'));
})
.remove();
//获取编译后的样式,改变为惰性加载
const sheet = [];
$('head')
.find('link[rel="stylesheet"]')
.each(function () {
sheet.push($(this)
.attr('href'));
})
.remove();
$('.loadScriptStyle')
.html(`
window.onload = function(){
LoadingScript(${JSON.stringify(src)})
LoadingSheet(${JSON.stringify(sheet)})
}
`);
}
},
src: './build/index.html' //could be an array of files
//dest: 'dist/index.html' //optional, if not specified the src file will be overwritten
}
},
copy: {
build: {
files: [
{
cwd: './scripts',
dest: './build',
expand: true,
src: ['**']
}
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-dom-munger');
grunt.registerTask('default', [
'dom_munger',
'copy'
]);
};