Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Chameleon
提交
5d27902d
C
Chameleon
项目概览
DiDi
/
Chameleon
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Chameleon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5d27902d
编写于
1月 22, 2019
作者:
Y
yangyiliang
提交者:
quyatong
1月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
miniapp npm中的组件绝对路径改为相对路径
上级
be2a2e33
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
5 deletion
+53
-5
packages/chameleon-tool-utils/src/index.js
packages/chameleon-tool-utils/src/index.js
+31
-4
packages/chameleon-tool-utils/test/index.test.js
packages/chameleon-tool-utils/test/index.test.js
+22
-0
packages/chameleon-tool/commanders/web/dev-server.js
packages/chameleon-tool/commanders/web/dev-server.js
+0
-1
未找到文件。
packages/chameleon-tool-utils/src/index.js
浏览文件 @
5d27902d
...
@@ -524,7 +524,9 @@ _.addNpmComponents = function (jsonObject, jsonFile, cmlType, context) {
...
@@ -524,7 +524,9 @@ _.addNpmComponents = function (jsonObject, jsonFile, cmlType, context) {
}
}
// 如果自动引入的组件与用户自定义组件重名则不自动引入
// 如果自动引入的组件与用户自定义组件重名则不自动引入
if
(
!~
customComsKeys
.
indexOf
(
npmcomName
))
{
if
(
!~
customComsKeys
.
indexOf
(
npmcomName
))
{
coms
[
item
.
name
]
=
item
.
refPath
;
// refPath 改为相对路径
let
refPath
=
_
.
npmRefPathToRelative
(
item
.
refPath
,
jsonFile
,
context
);
coms
[
item
.
name
]
=
refPath
;
}
}
})
})
}
}
...
@@ -637,10 +639,12 @@ _.handleComponentUrl = function (context, cmlFilePath, comPath, cmlType) {
...
@@ -637,10 +639,12 @@ _.handleComponentUrl = function (context, cmlFilePath, comPath, cmlType) {
}
}
if
(
~
filePath
.
indexOf
(
'
node_modules
'
))
{
if
(
~
filePath
.
indexOf
(
'
node_modules
'
))
{
refUrl
=
_
.
npmComponentRefPath
(
filePath
,
context
)
refUrl
=
_
.
npmComponentRefPath
(
filePath
,
context
);
// 改为相对路径
refUrl
=
_
.
npmRefPathToRelative
(
refUrl
,
filePath
,
context
);
}
else
{
}
else
{
// 改成
绝
对路径
// 改成
相
对路径
refUrl
=
_
.
handleRelativePath
(
cmlFilePath
,
filePath
);
refUrl
=
_
.
handleRelativePath
(
cmlFilePath
,
filePath
);
refUrl
=
refUrl
.
replace
(
new
RegExp
(
`(\\.cml|\\.
${
cmlType
}
\\.cml)`
),
''
);
refUrl
=
refUrl
.
replace
(
new
RegExp
(
`(\\.cml|\\.
${
cmlType
}
\\.cml)`
),
''
);
...
@@ -727,7 +731,30 @@ _.findInterfaceFile = function(context, cmlFilePath, comPath) {
...
@@ -727,7 +731,30 @@ _.findInterfaceFile = function(context, cmlFilePath, comPath) {
return
_
.
handleComponentUrl
(
context
,
cmlFilePath
,
comPath
,
'
interface
'
);
return
_
.
handleComponentUrl
(
context
,
cmlFilePath
,
comPath
,
'
interface
'
);
}
}
// 处理npm中组件的引用路径 root是项目根目录
/**
* @description 将/npm 的组件引用改为相对路径
* @param npmRefPath npm绝对引用路径 /npm/cml-ui/button/button
* @param cmlFilePath cml文件路径
* @param context 项目根目录
*/
_
.
npmRefPathToRelative
=
function
(
npmRefPath
,
cmlFilePath
,
context
)
{
if
(
npmRefPath
[
0
]
===
'
/
'
)
{
let
entryPath
=
_
.
getEntryPath
(
cmlFilePath
,
context
);
// pages/index/index.cml derLength = 2
let
dirLength
=
entryPath
.
split
(
'
/
'
).
length
-
1
;
let
relativePath
=
'
./
'
;
for
(
let
i
=
0
;
i
<
dirLength
;
i
++
)
{
relativePath
+=
'
../
'
;
}
npmRefPath
=
npmRefPath
.
slice
(
1
);
npmRefPath
=
relativePath
+
npmRefPath
;
return
npmRefPath
;
}
else
{
return
npmRefPath
;
}
}
// 处理npm中组件的引用路径 root是项目根目录 得到的是绝对路径/npm
_
.
npmComponentRefPath
=
function
(
componentAbsolutePath
,
context
)
{
_
.
npmComponentRefPath
=
function
(
componentAbsolutePath
,
context
)
{
let
refUrl
=
''
;
let
refUrl
=
''
;
refUrl
=
path
.
relative
(
context
,
componentAbsolutePath
);
refUrl
=
path
.
relative
(
context
,
componentAbsolutePath
);
...
...
packages/chameleon-tool-utils/test/index.test.js
浏览文件 @
5d27902d
...
@@ -473,5 +473,27 @@ describe('index.js', function () {
...
@@ -473,5 +473,27 @@ describe('index.js', function () {
expect
(
result2
).
to
.
be
.
equal
(
'
component
'
)
expect
(
result2
).
to
.
be
.
equal
(
'
component
'
)
expect
(
result3
).
to
.
be
.
equal
(
'
app
'
)
expect
(
result3
).
to
.
be
.
equal
(
'
app
'
)
})
it
(
'
npmRefPathToRelative
'
,
function
()
{
let
context
=
path
.
join
(
__dirname
,
'
./testlib/demo-project
'
);
let
npmRef
=
'
/npm/cml-ui/button/button
'
;
let
notNpmRef
=
'
./npm/cml-ui
'
;
let
file1
=
path
.
join
(
context
,
'
src/pages/page1/page1.cml
'
)
// ./../../npm
let
file2
=
path
.
join
(
context
,
'
src/pages/page1.cml
'
)
// ./../npm
let
file3
=
path
.
join
(
context
,
'
src/pages.cml
'
)
// ./npm
let
result1
=
_
.
npmRefPathToRelative
(
npmRef
,
file1
,
context
);
let
result2
=
_
.
npmRefPathToRelative
(
npmRef
,
file2
,
context
);
let
result3
=
_
.
npmRefPathToRelative
(
npmRef
,
file3
,
context
);
let
result4
=
_
.
npmRefPathToRelative
(
notNpmRef
,
file3
,
context
);
expect
(
result1
).
to
.
be
.
equal
(
'
./../../npm/cml-ui/button/button
'
);
expect
(
result2
).
to
.
be
.
equal
(
'
./../npm/cml-ui/button/button
'
);
expect
(
result3
).
to
.
be
.
equal
(
'
./npm/cml-ui/button/button
'
);
expect
(
result4
).
to
.
be
.
equal
(
notNpmRef
);
})
})
})
})
packages/chameleon-tool/commanders/web/dev-server.js
浏览文件 @
5d27902d
...
@@ -36,7 +36,6 @@ module.exports = function({webpackConfig, options, compiler}) {
...
@@ -36,7 +36,6 @@ module.exports = function({webpackConfig, options, compiler}) {
dynamicApiMiddleware
(
app
,
options
);
dynamicApiMiddleware
(
app
,
options
);
if
(
compiler
)
{
if
(
compiler
)
{
if
(
options
.
hot
===
true
)
{
if
(
options
.
hot
===
true
)
{
var
hotMiddleware
=
require
(
'
webpack-hot-middleware
'
)(
compiler
,
{
var
hotMiddleware
=
require
(
'
webpack-hot-middleware
'
)(
compiler
,
{
heartbeat
:
9000
,
heartbeat
:
9000
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录