Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
a2477d9a
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,发现更多精彩内容 >>
提交
a2477d9a
编写于
10月 20, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move /build/gulpfile.common to /build/lib/optimize.ts
上级
5ae54dd9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
247 addition
and
12 deletion
+247
-12
build/gulpfile.editor.js
build/gulpfile.editor.js
+1
-1
build/gulpfile.vscode.js
build/gulpfile.vscode.js
+1
-1
build/lib/optimize.js
build/lib/optimize.js
+233
-0
build/lib/optimize.ts
build/lib/optimize.ts
+12
-10
未找到文件。
build/gulpfile.editor.js
浏览文件 @
a2477d9a
...
...
@@ -6,7 +6,7 @@
var
gulp
=
require
(
'
gulp
'
);
var
path
=
require
(
'
path
'
);
var
util
=
require
(
'
./lib/util
'
);
var
common
=
require
(
'
./
gulpfile.common
'
);
var
common
=
require
(
'
./
lib/optimize
'
);
var
es
=
require
(
'
event-stream
'
);
var
File
=
require
(
'
vinyl
'
);
...
...
build/gulpfile.vscode.js
浏览文件 @
a2477d9a
...
...
@@ -21,7 +21,7 @@ const _ = require('underscore');
const
util
=
require
(
'
./lib/util
'
);
const
ext
=
require
(
'
./lib/extensions
'
);
const
buildfile
=
require
(
'
../src/buildfile
'
);
const
common
=
require
(
'
./
gulpfile.common
'
);
const
common
=
require
(
'
./
lib/optimize
'
);
const
nlsDev
=
require
(
'
vscode-nls-dev
'
);
const
root
=
path
.
dirname
(
__dirname
);
const
commit
=
util
.
getVersion
(
root
);
...
...
build/lib/optimize.js
0 → 100644
浏览文件 @
a2477d9a
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
var
path
=
require
(
'
path
'
);
var
gulp
=
require
(
'
gulp
'
);
var
sourcemaps
=
require
(
'
gulp-sourcemaps
'
);
var
filter
=
require
(
'
gulp-filter
'
);
var
minifyCSS
=
require
(
'
gulp-cssnano
'
);
var
uglify
=
require
(
'
gulp-uglify
'
);
var
es
=
require
(
'
event-stream
'
);
var
concat
=
require
(
'
gulp-concat
'
);
var
VinylFile
=
require
(
'
vinyl
'
);
var
bundle
=
require
(
'
./bundle
'
);
var
util
=
require
(
'
./util
'
);
var
i18n
=
require
(
'
./i18n
'
);
var
gulpUtil
=
require
(
'
gulp-util
'
);
var
flatmap
=
require
(
'
gulp-flatmap
'
);
var
pump
=
require
(
'
pump
'
);
var
REPO_ROOT_PATH
=
path
.
join
(
__dirname
,
'
../..
'
);
function
log
(
prefix
,
message
)
{
gulpUtil
.
log
(
gulpUtil
.
colors
.
cyan
(
'
[
'
+
prefix
+
'
]
'
),
message
);
}
exports
.
loaderConfig
=
function
(
emptyPaths
)
{
var
result
=
{
paths
:
{
'
vs
'
:
'
out-build/vs
'
,
'
vscode
'
:
'
empty:
'
},
nodeModules
:
emptyPaths
||
[]
};
result
[
'
vs/css
'
]
=
{
inlineResources
:
true
};
return
result
;
};
var
IS_OUR_COPYRIGHT_REGEXP
=
/Copyright
\(
C
\)
Microsoft Corporation/i
;
function
loader
(
bundledFileHeader
,
bundleLoader
)
{
var
sources
=
[
'
out-build/vs/loader.js
'
];
if
(
bundleLoader
)
{
sources
=
sources
.
concat
([
'
out-build/vs/css.js
'
,
'
out-build/vs/nls.js
'
]);
}
var
isFirst
=
true
;
return
(
gulp
.
src
(
sources
,
{
base
:
'
out-build
'
})
.
pipe
(
es
.
through
(
function
(
data
)
{
if
(
isFirst
)
{
isFirst
=
false
;
this
.
emit
(
'
data
'
,
new
VinylFile
({
path
:
'
fake
'
,
base
:
''
,
contents
:
new
Buffer
(
bundledFileHeader
)
}));
this
.
emit
(
'
data
'
,
data
);
}
else
{
this
.
emit
(
'
data
'
,
data
);
}
}))
.
pipe
(
util
.
loadSourcemaps
())
.
pipe
(
concat
(
'
vs/loader.js
'
))
.
pipe
(
es
.
mapSync
(
function
(
f
)
{
f
.
sourceMap
.
sourceRoot
=
util
.
toFileUri
(
path
.
join
(
REPO_ROOT_PATH
,
'
src
'
));
return
f
;
})));
}
function
toConcatStream
(
bundledFileHeader
,
sources
,
dest
)
{
var
useSourcemaps
=
/
\.
js$/
.
test
(
dest
)
&&
!
/
\.
nls
\.
js$/
.
test
(
dest
);
// If a bundle ends up including in any of the sources our copyright, then
// insert a fake source at the beginning of each bundle with our copyright
var
containsOurCopyright
=
false
;
for
(
var
i
=
0
,
len
=
sources
.
length
;
i
<
len
;
i
++
)
{
var
fileContents
=
sources
[
i
].
contents
;
if
(
IS_OUR_COPYRIGHT_REGEXP
.
test
(
fileContents
))
{
containsOurCopyright
=
true
;
break
;
}
}
if
(
containsOurCopyright
)
{
sources
.
unshift
({
path
:
null
,
contents
:
bundledFileHeader
});
}
var
treatedSources
=
sources
.
map
(
function
(
source
)
{
var
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
var
base
=
source
.
path
?
root
+
'
/out-build
'
:
''
;
return
new
VinylFile
({
path
:
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
,
base
:
base
,
contents
:
new
Buffer
(
source
.
contents
)
});
});
return
es
.
readArray
(
treatedSources
)
.
pipe
(
useSourcemaps
?
util
.
loadSourcemaps
()
:
es
.
through
())
.
pipe
(
concat
(
dest
));
}
function
toBundleStream
(
bundledFileHeader
,
bundles
)
{
return
es
.
merge
(
bundles
.
map
(
function
(
bundle
)
{
return
toConcatStream
(
bundledFileHeader
,
bundle
.
sources
,
bundle
.
dest
);
}));
}
/**
* opts:
* - entryPoints (for AMD files, will get bundled and get Copyright treatment)
* - otherSources (for non-AMD files that should get Copyright treatment)
* - resources (svg, etc.)
* - loaderConfig
* - bundleLoader (boolean - true by default - append css and nls to loader)
* - header (basically the Copyright treatment)
* - bundleInfo (boolean - emit bundleInfo.json file)
* - out (out folder name)
*/
exports
.
optimizeTask
=
function
(
opts
)
{
var
entryPoints
=
opts
.
entryPoints
;
var
otherSources
=
opts
.
otherSources
;
var
resources
=
opts
.
resources
;
var
loaderConfig
=
opts
.
loaderConfig
;
var
bundledFileHeader
=
opts
.
header
;
var
bundleLoader
=
(
typeof
opts
.
bundleLoader
===
'
undefined
'
?
true
:
opts
.
bundleLoader
);
var
out
=
opts
.
out
;
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
));
}
toBundleStream
(
bundledFileHeader
,
result
.
files
).
pipe
(
bundlesStream
);
// Remove css inlined resources
var
filteredResources
=
resources
.
slice
();
result
.
cssInlinedResources
.
forEach
(
function
(
resource
)
{
if
(
process
.
env
[
'
VSCODE_BUILD_VERBOSE
'
])
{
log
(
'
optimizer
'
,
'
excluding inlined:
'
+
resource
);
}
filteredResources
.
push
(
'
!
'
+
resource
);
});
gulp
.
src
(
filteredResources
,
{
base
:
'
out-build
'
}).
pipe
(
resourcesStream
);
var
bundleInfoArray
=
[];
if
(
opts
.
bundleInfo
)
{
bundleInfoArray
.
push
(
new
VinylFile
({
path
:
'
bundleInfo.json
'
,
base
:
'
.
'
,
contents
:
new
Buffer
(
JSON
.
stringify
(
result
.
bundleData
,
null
,
'
\t
'
))
}));
}
es
.
readArray
(
bundleInfoArray
).
pipe
(
bundleInfoStream
);
});
var
otherSourcesStream
=
es
.
through
();
var
otherSourcesStreamArr
=
[];
gulp
.
src
(
otherSources
,
{
base
:
'
out-build
'
})
.
pipe
(
es
.
through
(
function
(
data
)
{
otherSourcesStreamArr
.
push
(
toConcatStream
(
bundledFileHeader
,
[
data
],
data
.
relative
));
},
function
()
{
if
(
!
otherSourcesStreamArr
.
length
)
{
setTimeout
(
function
()
{
otherSourcesStream
.
emit
(
'
end
'
);
},
0
);
}
else
{
es
.
merge
(
otherSourcesStreamArr
).
pipe
(
otherSourcesStream
);
}
}));
var
result
=
es
.
merge
(
loader
(
bundledFileHeader
,
bundleLoader
),
bundlesStream
,
otherSourcesStream
,
resourcesStream
,
bundleInfoStream
);
return
result
.
pipe
(
sourcemaps
.
write
(
'
./
'
,
{
sourceRoot
:
null
,
addComment
:
true
,
includeContent
:
true
}))
.
pipe
(
i18n
.
processNlsFiles
({
fileHeader
:
bundledFileHeader
}))
.
pipe
(
gulp
.
dest
(
out
));
};
};
/**
* Wrap around uglify and allow the preserveComments function
* to have a file "context" to include our copyright only once per file.
*/
function
uglifyWithCopyrights
()
{
var
preserveComments
=
function
(
f
)
{
return
function
(
node
,
comment
)
{
var
text
=
comment
.
value
;
var
type
=
comment
.
type
;
if
(
/@minifier_do_not_preserve/
.
test
(
text
))
{
return
false
;
}
var
isOurCopyright
=
IS_OUR_COPYRIGHT_REGEXP
.
test
(
text
);
if
(
isOurCopyright
)
{
if
(
f
.
__hasOurCopyright
)
{
return
false
;
}
f
.
__hasOurCopyright
=
true
;
return
true
;
}
if
(
'
comment2
'
===
type
)
{
// check for /*!. Note that text doesn't contain leading /*
return
(
text
.
length
>
0
&&
text
[
0
]
===
'
!
'
)
||
/@preserve|license|@cc_on|copyright/i
.
test
(
text
);
}
else
if
(
'
comment1
'
===
type
)
{
return
/license|copyright/i
.
test
(
text
);
}
return
false
;
};
};
var
input
=
es
.
through
();
var
output
=
input
.
pipe
(
flatmap
(
function
(
stream
,
f
)
{
return
stream
.
pipe
(
uglify
({
preserveComments
:
preserveComments
(
f
)
}));
}));
return
es
.
duplex
(
input
,
output
);
}
exports
.
minifyTask
=
function
(
src
,
sourceMapBaseUrl
)
{
var
sourceMappingURL
=
sourceMapBaseUrl
&&
(
function
(
f
)
{
return
(
sourceMapBaseUrl
+
"
/
"
+
f
.
relative
+
"
.map
"
);
});
return
function
(
cb
)
{
var
jsFilter
=
filter
(
'
**/*.js
'
,
{
restore
:
true
});
var
cssFilter
=
filter
(
'
**/*.css
'
,
{
restore
:
true
});
pump
(
gulp
.
src
([
src
+
'
/**
'
,
'
!
'
+
src
+
'
/**/*.map
'
]),
jsFilter
,
sourcemaps
.
init
({
loadMaps
:
true
}),
uglifyWithCopyrights
(),
jsFilter
.
restore
,
cssFilter
,
minifyCSS
({
reduceIdents
:
false
}),
cssFilter
.
restore
,
sourcemaps
.
write
(
'
./
'
,
{
sourceMappingURL
:
sourceMappingURL
,
sourceRoot
:
null
,
includeContent
:
true
,
addComment
:
true
}),
gulp
.
dest
(
src
+
'
-min
'
),
function
(
err
)
{
if
(
err
instanceof
uglify
.
GulpUglifyError
)
{
console
.
error
(
"
Uglify error in '
"
+
(
err
.
cause
&&
err
.
cause
.
filename
)
+
"
'
"
);
}
cb
(
err
);
});
};
};
build/
gulpfile.common.j
s
→
build/
lib/optimize.t
s
浏览文件 @
a2477d9a
...
...
@@ -13,14 +13,16 @@ const minifyCSS = require('gulp-cssnano');
const
uglify
=
require
(
'
gulp-uglify
'
);
const
es
=
require
(
'
event-stream
'
);
const
concat
=
require
(
'
gulp-concat
'
);
const
File
=
require
(
'
vinyl
'
);
const
bundle
=
require
(
'
./
lib/
bundle
'
);
const
util
=
require
(
'
./
lib/
util
'
);
const
i18n
=
require
(
'
./
lib/
i18n
'
);
const
Vinyl
File
=
require
(
'
vinyl
'
);
const
bundle
=
require
(
'
./bundle
'
);
const
util
=
require
(
'
./util
'
);
const
i18n
=
require
(
'
./i18n
'
);
const
gulpUtil
=
require
(
'
gulp-util
'
);
const
flatmap
=
require
(
'
gulp-flatmap
'
);
const
pump
=
require
(
'
pump
'
);
const
REPO_ROOT_PATH
=
path
.
join
(
__dirname
,
'
../..
'
);
function
log
(
prefix
,
message
)
{
gulpUtil
.
log
(
gulpUtil
.
colors
.
cyan
(
'
[
'
+
prefix
+
'
]
'
),
message
);
}
...
...
@@ -59,7 +61,7 @@ function loader(bundledFileHeader, bundleLoader) {
.
pipe
(
es
.
through
(
function
(
data
)
{
if
(
isFirst
)
{
isFirst
=
false
;
this
.
emit
(
'
data
'
,
new
File
({
this
.
emit
(
'
data
'
,
new
Vinyl
File
({
path
:
'
fake
'
,
base
:
''
,
contents
:
new
Buffer
(
bundledFileHeader
)
...
...
@@ -72,7 +74,7 @@ function loader(bundledFileHeader, bundleLoader) {
.
pipe
(
util
.
loadSourcemaps
())
.
pipe
(
concat
(
'
vs/loader.js
'
))
.
pipe
(
es
.
mapSync
(
function
(
f
)
{
f
.
sourceMap
.
sourceRoot
=
util
.
toFileUri
(
path
.
join
(
path
.
dirname
(
__dirname
)
,
'
src
'
));
f
.
sourceMap
.
sourceRoot
=
util
.
toFileUri
(
path
.
join
(
REPO_ROOT_PATH
,
'
src
'
));
return
f
;
}))
);
...
...
@@ -100,10 +102,10 @@ function toConcatStream(bundledFileHeader, sources, dest) {
}
const
treatedSources
=
sources
.
map
(
function
(
source
)
{
const
root
=
source
.
path
?
path
.
dirname
(
__dirname
)
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
base
=
source
.
path
?
root
+
'
/out-build
'
:
''
;
return
new
File
({
return
new
Vinyl
File
({
path
:
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
,
base
:
base
,
contents
:
new
Buffer
(
source
.
contents
)
...
...
@@ -163,7 +165,7 @@ exports.optimizeTask = function(opts) {
const
bundleInfoArray
=
[];
if
(
opts
.
bundleInfo
)
{
bundleInfoArray
.
push
(
new
File
({
bundleInfoArray
.
push
(
new
Vinyl
File
({
path
:
'
bundleInfo.json
'
,
base
:
'
.
'
,
contents
:
new
Buffer
(
JSON
.
stringify
(
result
.
bundleData
,
null
,
'
\t
'
))
...
...
@@ -280,4 +282,4 @@ exports.minifyTask = function (src, sourceMapBaseUrl) {
cb
(
err
);
});
};
};
\ No newline at end of file
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录