-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatfile.js
75 lines (59 loc) · 1.61 KB
/
matfile.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
/**
* Created by yingchun.fyc@alibaba-inc.com on 2017/4/24.
*/
var mat = require('mat')
var less = require('mat-less')
var combineTool = require('magix-combine')
var combineToolConfig = require('./combine-tool-config')
var path = require('path')
//magix-combine工具
combineTool.config(combineToolConfig)
//分析js,打包view
function analyse() {
return function* combine(next) {
// console.log('文件路径:', this.path)
yield next
let body = this.body.toString()
if (body == 'Not Found') {
throw new Error('路径:' + this.path + ' 对应的文件没有找到')
}
let file = path.join(__dirname, this.path)
body = yield combineTool.processContent(path.join(__dirname, this.path), '', body)
this.body = body
}
}
mat.env({
port: 8281,
combohandler: true
})
mat.task('combine', function(){
mat.url([/\.js(\?.+)?$/])
.use(analyse())
})
// 预编译less
mat.task('less', function(){
mat.url([/\.css/]).rewrite([
[/\.css/g, '.less']
])
.use(less())
})
mat.task('pushState', function () {
mat.url([/^((?!\.(css|less|js|html|ico|swf)).)*$/])
.rewrite([
[/(\/.*)+/, 'index.html']
])
})
mat.task('proxy', function(){
mat.url([/\.json/]).use(function *(next){
this.proxyPass = 'rapapi.org/mockjsdata/18155' // proxyPass会被mat内部处理
yield next
})
})
mat.task('pushState_online', function () {
mat.url([/^((?!\.(css|less|js|html|ico|swf)).)*$/])
.rewrite([
[/(\/.*)+/, 'index-online.html']
])
})
mat.task('default', ['less', 'pushState', 'combine', 'proxy'])
mat.task('compress', ['pushState_online', 'combine', 'proxy'])