Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/uni-cli-shared/src/mp/assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import fs from 'fs'
import path from 'path'
import { normalizePath } from '../vite/plugins/vitejs/utils'
import { parseMiniProgramPagesJson } from '../json'

const EXTNAMES = [
'.png',
'.jpg',
Expand All @@ -24,3 +28,28 @@ export function isMiniProgramAssetFile(filename: string) {
}
return EXTNAMES.includes(path.extname(filename))
}

export function createCopyComponentDirs(dir: string) {
const dirs = [dir]
dirs.push(normalizePath(path.join('uni_modules/*/' + dir + '/**/*')))
const { appJson } = parseMiniProgramPagesJson(
fs.readFileSync(
path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'),
'utf8'
),
process.env.UNI_PLATFORM,
{ subpackages: true }
)
const roots: string[] = Object.values(
appJson.subPackages || appJson.subpackages || {}
)
.filter(Boolean)
.map(({ root }) => root)
roots.forEach((root) => {
dirs.push(
normalizePath(path.join(root, dir)),
normalizePath(path.join(root, 'uni_modules/*/' + dir + '/**/*'))
)
})
return dirs
}
3 changes: 2 additions & 1 deletion packages/uni-mp-alipay/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
COMPONENT_ON_LINK,
type MiniProgramCompilerOptions,
copyMiniProgramPluginJson,
createCopyComponentDirs,
createCopyPluginTarget,
createTransformComponentLink,
getNativeTags,
Expand Down Expand Up @@ -99,7 +100,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
...(process.env.UNI_MP_PLUGIN ? [copyMiniProgramPluginJson] : []),
{
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-baidu/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
type MiniProgramCompilerOptions,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
// transformMatchMedia,
Expand Down Expand Up @@ -95,7 +96,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [createCopyPluginTarget(['ext.json'])],
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-harmony/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
type MiniProgramCompilerOptions,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
transformRef,
Expand Down Expand Up @@ -61,7 +62,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
{
src: ['ascf.config.json'],
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-jd/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
COMPONENT_CUSTOM_HIDDEN_BIND,
type MiniProgramCompilerOptions,
createCopyComponentDirs,
getNativeTags,
transformComponentLink,
transformRef,
Expand Down Expand Up @@ -80,7 +81,7 @@ export const options: UniMiniProgramPluginOptions = {
/**
* 静态资源,配置的目录,在 uni_modules 中同样支持
*/
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
{
// FileWatcher这个类监听的文件,文件改动触发整体编译?编译什么?
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-kuaishou/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
type MiniProgramCompilerOptions,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
transformComponentLink,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
{
src: ['project.private.config.json'],
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-qq/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
COMPONENT_CUSTOM_HIDDEN,
type MiniProgramCompilerOptions,
createCopyComponentDirs,
getNativeTags,
transformComponentLink,
// transformMatchMedia,
Expand Down Expand Up @@ -83,7 +84,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
{
src: ['custom-tab-bar', 'project.config.json'],
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-toutiao/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
import {
COMPONENT_CUSTOM_HIDDEN_BIND,
type MiniProgramCompilerOptions,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
transformComponentLink,
Expand Down Expand Up @@ -89,7 +90,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': resolveMiniProgramRuntime(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [...commonCopyTargets, createCopyPluginTarget(['ext.json'])],
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-weixin/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type MiniProgramCompilerOptions,
copyMiniProgramPluginJson,
copyMiniProgramThemeJson,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
transformComponentLink,
Expand Down Expand Up @@ -151,7 +152,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': resolveMiniProgramRuntime(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
...(process.env.UNI_MP_PLUGIN ? [copyMiniProgramPluginJson] : []),
{
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-mp-xhs/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import {
type MiniProgramCompilerOptions,
createCopyComponentDirs,
createCopyPluginTarget,
getNativeTags,
transformComponentLink,
Expand Down Expand Up @@ -89,7 +90,7 @@ export const options: UniMiniProgramPluginOptions = {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {
assets: [COMPONENTS_DIR],
assets: createCopyComponentDirs(COMPONENTS_DIR),
targets: [
// ...(process.env.UNI_MP_PLUGIN ? [copyMiniProgramPluginJson] : []),
{
Expand Down
Loading