Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
a9bc0a6f
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a9bc0a6f
编写于
12月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: converts the filepath of the asset (#3100)
上级
76698a51
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
10 deletion
+92
-10
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
...s/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
+88
-5
packages/uni-mp-toutiao/dist/uni.compiler.js
packages/uni-mp-toutiao/dist/uni.compiler.js
+2
-3
packages/uni-mp-toutiao/src/compiler/index.ts
packages/uni-mp-toutiao/src/compiler/index.ts
+2
-2
未找到文件。
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
浏览文件 @
a9bc0a6f
...
...
@@ -5,7 +5,7 @@ import fs, { promises as fsp } from 'fs'
import
{
Plugin
}
from
'
../plugin
'
import
{
ResolvedConfig
}
from
'
../config
'
import
{
cleanUrl
,
normalizePath
}
from
'
../utils
'
import
{
PluginContext
,
RenderedChunk
}
from
'
rollup
'
import
type
{
OutputOptions
,
PluginContext
,
RenderedChunk
}
from
'
rollup
'
import
MagicString
from
'
magic-string
'
import
{
createHash
}
from
'
crypto
'
...
...
@@ -150,6 +150,83 @@ export function getAssetFilename(
):
string
|
undefined
{
return
assetHashToFilenameMap
.
get
(
config
)?.
get
(
hash
)
}
/**
* converts the source filepath of the asset to the output filename based on the assetFileNames option. \
* this function imitates the behavior of rollup.js. \
* https://rollupjs.org/guide/en/#outputassetfilenames
*
* @example
* ```ts
* const content = Buffer.from('text');
* const fileName = assetFileNamesToFileName(
* 'assets/[name].[hash][extname]',
* '/path/to/file.txt',
* getAssetHash(content),
* content
* )
* // fileName: 'assets/file.982d9e3e.txt'
* ```
*
* @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
* @param file filepath of the asset
* @param contentHash hash of the asset. used for `'[hash]'` placeholder
* @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
* @returns output filename
*/
export
function
assetFileNamesToFileName
(
assetFileNames
:
Exclude
<
OutputOptions
[
'
assetFileNames
'
],
undefined
>
,
file
:
string
,
contentHash
:
string
,
content
:
string
|
Buffer
):
string
{
const
basename
=
path
.
basename
(
file
)
// placeholders for `assetFileNames`
// `hash` is slightly different from the rollup's one
const
extname
=
path
.
extname
(
basename
)
const
ext
=
extname
.
substring
(
1
)
const
name
=
basename
.
slice
(
0
,
-
extname
.
length
)
const
hash
=
contentHash
if
(
typeof
assetFileNames
===
'
function
'
)
{
assetFileNames
=
assetFileNames
({
name
:
file
,
source
:
content
,
type
:
'
asset
'
,
})
if
(
typeof
assetFileNames
!==
'
string
'
)
{
throw
new
TypeError
(
'
assetFileNames must return a string
'
)
}
}
else
if
(
typeof
assetFileNames
!==
'
string
'
)
{
throw
new
TypeError
(
'
assetFileNames must be a string or a function
'
)
}
const
fileName
=
assetFileNames
.
replace
(
/
\[\w
+
\]
/g
,
(
placeholder
:
string
):
string
=>
{
switch
(
placeholder
)
{
case
'
[ext]
'
:
return
ext
case
'
[extname]
'
:
return
extname
case
'
[hash]
'
:
return
hash
case
'
[name]
'
:
return
name
}
throw
new
Error
(
`invalid placeholder
${
placeholder
}
in assetFileNames "
${
assetFileNames
}
"`
)
}
)
return
fileName
}
/**
* Register an asset to be emitted as part of the bundle (if necessary)
* and returns the resolved public URL
...
...
@@ -183,10 +260,16 @@ function fileToBuiltUrl(
const
contentHash
=
getAssetHash
(
content
)
const
{
search
,
hash
}
=
parseUrl
(
id
)
const
postfix
=
(
search
||
''
)
+
(
hash
||
''
)
const
fileName
=
path
.
posix
.
relative
(
normalizePath
(
process
.
env
.
UNI_INPUT_DIR
),
file
)
const
inputDir
=
normalizePath
(
process
.
env
.
UNI_INPUT_DIR
)
let
fileName
=
file
.
startsWith
(
inputDir
)
?
path
.
posix
.
relative
(
inputDir
,
file
)
:
assetFileNamesToFileName
(
path
.
posix
.
join
(
config
.
build
.
assetsDir
,
'
[name].[hash][extname]
'
),
file
,
contentHash
,
content
)
if
(
!
map
.
has
(
contentHash
))
{
map
.
set
(
contentHash
,
fileName
)
...
...
packages/uni-mp-toutiao/dist/uni.compiler.js
浏览文件 @
a9bc0a6f
'
use strict
'
;
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
initMiniProgramPlugin
=
require
(
'
@dcloudio/uni-mp-vite
'
);
var
path
=
require
(
'
path
'
);
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
uniMpCompiler
=
require
(
'
@dcloudio/uni-mp-compiler
'
);
var
compilerCore
=
require
(
'
@vue/compiler-core
'
);
...
...
@@ -134,8 +134,7 @@ const uniMiniProgramToutiaoPlugin = {
__VUE_CREATED_DEFERRED__
:
true
,
},
build
:
{
// 头条支持本地资源
assetsInlineLimit
:
0
,
assetsInlineLimit
:
uniCliShared
.
ASSETS_INLINE_LIMIT
,
},
};
},
...
...
packages/uni-mp-toutiao/src/compiler/index.ts
浏览文件 @
a9bc0a6f
import
{
Plugin
}
from
'
vite
'
import
{
ASSETS_INLINE_LIMIT
}
from
'
@dcloudio/uni-cli-shared
'
import
initMiniProgramPlugin
from
'
@dcloudio/uni-mp-vite
'
import
{
options
}
from
'
./options
'
...
...
@@ -11,8 +12,7 @@ const uniMiniProgramToutiaoPlugin: Plugin = {
__VUE_CREATED_DEFERRED__
:
true
,
},
build
:
{
// 头条支持本地资源
assetsInlineLimit
:
0
,
assetsInlineLimit
:
ASSETS_INLINE_LIMIT
,
},
}
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录