Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
27dae4d2
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
27dae4d2
编写于
6月 08, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bundler: generate bundleInfo, remove duplicated TS boilerplate
上级
d3267ffd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
154 addition
and
10 deletion
+154
-10
build/gulpfile.common.js
build/gulpfile.common.js
+14
-1
build/lib/bundle.js
build/lib/bundle.js
+63
-4
build/lib/bundle.ts
build/lib/bundle.ts
+77
-5
未找到文件。
build/gulpfile.common.js
浏览文件 @
27dae4d2
...
...
@@ -128,6 +128,7 @@ function toBundleStream(bundledFileHeader, bundles) {
* - resources (svg, etc.)
* - loaderConfig
* - header (basically the Copyright treatment)
* - bundleInfo (boolean - emit bundleInfo.json file)
* - out (out folder name)
*/
exports
.
optimizeTask
=
function
(
opts
)
{
...
...
@@ -141,6 +142,7 @@ exports.optimizeTask = function(opts) {
return
function
()
{
var
bundlesStream
=
es
.
through
();
// this stream will contain the bundled files
var
resourcesStream
=
es
.
through
();
// this stream will contain the resources
var
bundleInfoStream
=
es
.
through
();
// this stream will contain bundleInfo.json
bundle
.
bundle
(
entryPoints
,
loaderConfig
,
function
(
err
,
result
)
{
if
(
err
)
{
return
bundlesStream
.
emit
(
'
error
'
,
JSON
.
stringify
(
err
));
}
...
...
@@ -155,6 +157,16 @@ exports.optimizeTask = function(opts) {
filteredResources
.
push
(
'
!
'
+
resource
);
});
gulp
.
src
(
filteredResources
,
{
base
:
'
out-build
'
}).
pipe
(
resourcesStream
);
var
bundleInfoArray
=
[];
if
(
opts
.
bundleInfo
)
{
bundleInfoArray
.
push
(
new
File
({
path
:
'
bundleInfo.json
'
,
base
:
'
.
'
,
contents
:
new
Buffer
(
JSON
.
stringify
(
result
.
bundleData
,
null
,
'
\t
'
))
}));
}
es
.
readArray
(
bundleInfoArray
).
pipe
(
bundleInfoStream
);
});
var
otherSourcesStream
=
es
.
through
();
...
...
@@ -175,7 +187,8 @@ exports.optimizeTask = function(opts) {
loader
(
bundledFileHeader
),
bundlesStream
,
otherSourcesStream
,
resourcesStream
resourcesStream
,
bundleInfoStream
);
return
result
...
...
build/lib/bundle.js
浏览文件 @
27dae4d2
...
...
@@ -23,11 +23,12 @@ function bundle(entryPoints, config, callback) {
loader
.
config
(
config
);
loader
(
Object
.
keys
(
entryPointsMap
),
function
()
{
var
modules
=
loader
.
getBuildInfo
();
var
resultFiles
=
emitEntryPoints
(
modules
,
entryPointsMap
);
var
partialResult
=
emitEntryPoints
(
modules
,
entryPointsMap
);
var
cssInlinedResources
=
loader
(
'
vs/css
'
).
getInlinedResources
();
callback
(
null
,
{
files
:
resultFiles
,
cssInlinedResources
:
cssInlinedResources
files
:
partialResult
.
files
,
cssInlinedResources
:
cssInlinedResources
,
bundleData
:
partialResult
.
bundleData
});
},
function
(
err
)
{
return
callback
(
err
,
null
);
});
}
...
...
@@ -44,6 +45,10 @@ function emitEntryPoints(modules, entryPoints) {
var
sortedModules
=
topologicalSort
(
modulesGraph
);
var
result
=
[];
var
usedPlugins
=
{};
var
bundleData
=
{
graph
:
modulesGraph
,
bundles
:
{}
};
Object
.
keys
(
entryPoints
).
forEach
(
function
(
moduleToBundle
)
{
var
info
=
entryPoints
[
moduleToBundle
];
var
rootNodes
=
[
moduleToBundle
].
concat
(
info
.
include
||
[]);
...
...
@@ -58,6 +63,7 @@ function emitEntryPoints(modules, entryPoints) {
var
includedModules
=
sortedModules
.
filter
(
function
(
module
)
{
return
allDependencies
[
module
];
});
bundleData
.
bundles
[
moduleToBundle
]
=
includedModules
;
var
res
=
emitEntryPoint
(
modulesMap
,
modulesGraph
,
moduleToBundle
,
includedModules
);
result
=
result
.
concat
(
res
.
files
);
for
(
var
pluginName
in
res
.
usedPlugins
)
{
...
...
@@ -79,7 +85,60 @@ function emitEntryPoints(modules, entryPoints) {
plugin
.
finishBuild
(
write
);
}
});
return
result
;
return
{
files
:
removeDuplicateTSBoilerplate
(
result
),
bundleData
:
bundleData
};
}
function
removeDuplicateTSBoilerplate
(
destFiles
)
{
// Taken from typescript compiler => emitFiles
var
BOILERPLATE
=
[
{
start
:
/^var __extends/
,
end
:
/^};$/
},
{
start
:
/^var __assign/
,
end
:
/^};$/
},
{
start
:
/^var __decorate/
,
end
:
/^};$/
},
{
start
:
/^var __metadata/
,
end
:
/^};$/
},
{
start
:
/^var __param/
,
end
:
/^};$/
},
{
start
:
/^var __awaiter/
,
end
:
/^};$/
},
];
destFiles
.
forEach
(
function
(
destFile
)
{
var
SEEN_BOILERPLATE
=
[];
destFile
.
sources
.
forEach
(
function
(
source
)
{
var
lines
=
source
.
contents
.
split
(
/
\r\n
|
\n
|
\r
/
);
var
newLines
=
[];
var
IS_REMOVING_BOILERPLATE
=
false
,
END_BOILERPLATE
;
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
var
line
=
lines
[
i
];
if
(
IS_REMOVING_BOILERPLATE
)
{
newLines
.
push
(
''
);
if
(
END_BOILERPLATE
.
test
(
line
))
{
IS_REMOVING_BOILERPLATE
=
false
;
}
}
else
{
for
(
var
j
=
0
;
j
<
BOILERPLATE
.
length
;
j
++
)
{
var
boilerplate
=
BOILERPLATE
[
j
];
if
(
boilerplate
.
start
.
test
(
line
))
{
if
(
SEEN_BOILERPLATE
[
j
])
{
IS_REMOVING_BOILERPLATE
=
true
;
END_BOILERPLATE
=
boilerplate
.
end
;
}
else
{
SEEN_BOILERPLATE
[
j
]
=
true
;
}
}
}
if
(
IS_REMOVING_BOILERPLATE
)
{
newLines
.
push
(
''
);
}
else
{
newLines
.
push
(
line
);
}
}
}
source
.
contents
=
newLines
.
join
(
'
\n
'
);
});
});
return
destFiles
;
}
function
emitEntryPoint
(
modulesMap
,
deps
,
entryPoint
,
includedModules
)
{
var
mainResult
=
{
...
...
build/lib/bundle.ts
浏览文件 @
27dae4d2
...
...
@@ -70,9 +70,20 @@ export interface IConcatFile {
sources
:
IFile
[];
}
export
interface
IBundleData
{
graph
:
IGraph
;
bundles
:
{[
moduleId
:
string
]:
string
[];};
}
export
interface
IBundleResult
{
files
:
IConcatFile
[];
cssInlinedResources
:
string
[];
bundleData
:
IBundleData
;
}
interface
IPartialBundleResult
{
files
:
IConcatFile
[];
bundleData
:
IBundleData
;
}
export
interface
ILoaderConfig
{
...
...
@@ -100,16 +111,17 @@ export function bundle(entryPoints:IEntryPoint[], config:ILoaderConfig, callback
loader
(
Object
.
keys
(
entryPointsMap
),
()
=>
{
let
modules
=
<
IBuildModuleInfo
[]
>
loader
.
getBuildInfo
();
let
resultFiles
=
emitEntryPoints
(
modules
,
entryPointsMap
);
let
partialResult
=
emitEntryPoints
(
modules
,
entryPointsMap
);
let
cssInlinedResources
=
loader
(
'
vs/css
'
).
getInlinedResources
();
callback
(
null
,
{
files
:
resultFiles
,
cssInlinedResources
:
cssInlinedResources
files
:
partialResult
.
files
,
cssInlinedResources
:
cssInlinedResources
,
bundleData
:
partialResult
.
bundleData
});
},
(
err
)
=>
callback
(
err
,
null
));
}
function
emitEntryPoints
(
modules
:
IBuildModuleInfo
[],
entryPoints
:
IEntryPointMap
):
I
ConcatFile
[]
{
function
emitEntryPoints
(
modules
:
IBuildModuleInfo
[],
entryPoints
:
IEntryPointMap
):
I
PartialBundleResult
{
let
modulesMap
:
IBuildModuleInfoMap
=
{};
modules
.
forEach
((
m
:
IBuildModuleInfo
)
=>
{
modulesMap
[
m
.
id
]
=
m
;
...
...
@@ -124,6 +136,10 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
let
result
:
IConcatFile
[]
=
[];
let
usedPlugins
:
IPluginMap
=
{};
let
bundleData
:
IBundleData
=
{
graph
:
modulesGraph
,
bundles
:
{}
};
Object
.
keys
(
entryPoints
).
forEach
((
moduleToBundle
:
string
)
=>
{
let
info
=
entryPoints
[
moduleToBundle
];
...
...
@@ -142,6 +158,8 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
return
allDependencies
[
module
];
});
bundleData
.
bundles
[
moduleToBundle
]
=
includedModules
;
let
res
=
emitEntryPoint
(
modulesMap
,
modulesGraph
,
moduleToBundle
,
includedModules
);
result
=
result
.
concat
(
res
.
files
);
...
...
@@ -166,7 +184,61 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
}
});
return
result
;
return
{
files
:
removeDuplicateTSBoilerplate
(
result
),
bundleData
:
bundleData
};
}
function
removeDuplicateTSBoilerplate
(
destFiles
:
IConcatFile
[]):
IConcatFile
[]
{
// Taken from typescript compiler => emitFiles
let
BOILERPLATE
=
[
{
start
:
/^var __extends/
,
end
:
/^};$/
},
{
start
:
/^var __assign/
,
end
:
/^};$/
},
{
start
:
/^var __decorate/
,
end
:
/^};$/
},
{
start
:
/^var __metadata/
,
end
:
/^};$/
},
{
start
:
/^var __param/
,
end
:
/^};$/
},
{
start
:
/^var __awaiter/
,
end
:
/^};$/
},
];
destFiles
.
forEach
((
destFile
)
=>
{
let
SEEN_BOILERPLATE
=
[];
destFile
.
sources
.
forEach
((
source
)
=>
{
let
lines
=
source
.
contents
.
split
(
/
\r\n
|
\n
|
\r
/
);
let
newLines
:
string
[]
=
[];
let
IS_REMOVING_BOILERPLATE
=
false
,
END_BOILERPLATE
:
RegExp
;
for
(
let
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
let
line
=
lines
[
i
];
if
(
IS_REMOVING_BOILERPLATE
)
{
newLines
.
push
(
''
);
if
(
END_BOILERPLATE
.
test
(
line
))
{
IS_REMOVING_BOILERPLATE
=
false
;
}
}
else
{
for
(
let
j
=
0
;
j
<
BOILERPLATE
.
length
;
j
++
)
{
let
boilerplate
=
BOILERPLATE
[
j
];
if
(
boilerplate
.
start
.
test
(
line
))
{
if
(
SEEN_BOILERPLATE
[
j
])
{
IS_REMOVING_BOILERPLATE
=
true
;
END_BOILERPLATE
=
boilerplate
.
end
;
}
else
{
SEEN_BOILERPLATE
[
j
]
=
true
;
}
}
}
if
(
IS_REMOVING_BOILERPLATE
)
{
newLines
.
push
(
''
);
}
else
{
newLines
.
push
(
line
);
}
}
}
source
.
contents
=
newLines
.
join
(
'
\n
'
);
});
});
return
destFiles
;
}
interface
IPluginMap
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录