Skip to content

feat: support src root json import#27

Open
Aysnine wants to merge 1 commit intovue-mini:mainfrom
Aysnine:main
Open

feat: support src root json import#27
Aysnine wants to merge 1 commit intovue-mini:mainfrom
Aysnine:main

Conversation

@Aysnine
Copy link
Copy Markdown

@Aysnine Aysnine commented Feb 22, 2026

支持导入 src 下的 json 配置,如:

import themes from '@/theme.json';
import app from '@/app.json';

这在自定义 tab-bar 和引用主题色时很有帮助。

实现方式:

将 src/*.json 文件复制为 *.json.js 文件,内容为 js。

const cb = async (filePath) => {
  if (filePath.endsWith('.js')) {
    await processScript(filePath);
    return;
  }

  if (filePath.endsWith('.html')) {
    await processTemplate(filePath);
    return;
  }

  if (filePath.endsWith('.css')) {
    await processStyle(filePath);
    return;
  }

  // 在处理该文件时没有加 return,所以打包时,原来的 json 文件也会被保留。
  if (/src\/[^/]+\.json$/.test(filePath)) {
    await processRootJson(filePath);
  }

  await fs.copy(filePath, filePath.replace('src', 'dist'));
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant