manifestJson.js 1.3 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniManifestJsonPlugin = void 0;
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
function uniManifestJsonPlugin() {
fxy060608's avatar
fxy060608 已提交
6
    let manifestJson;
fxy060608's avatar
fxy060608 已提交
7 8 9 10 11 12 13 14
    return uni_cli_shared_1.defineUniManifestJsonPlugin((opts) => {
        return {
            name: 'vite:uni-app-manifest-json',
            enforce: 'pre',
            transform(code, id) {
                if (!opts.filter(id)) {
                    return;
                }
fxy060608's avatar
fxy060608 已提交
15
                manifestJson = uni_cli_shared_1.normalizeAppManifestJson(JSON.parse(code), uni_cli_shared_1.parsePagesJsonOnce(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM));
fxy060608's avatar
fxy060608 已提交
16 17 18
                return '';
            },
            generateBundle() {
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24
                // 生成一个空的app-config.js,兼容基座已有规范
                this.emitFile({
                    fileName: `app-config.js`,
                    type: 'asset',
                    source: '(function(){})();',
                });
fxy060608's avatar
fxy060608 已提交
25 26 27 28 29
                this.emitFile({
                    fileName: `manifest.json`,
                    type: 'asset',
                    source: JSON.stringify(manifestJson, null, 2),
                });
fxy060608's avatar
fxy060608 已提交
30 31 32 33 34
            },
        };
    });
}
exports.uniManifestJsonPlugin = uniManifestJsonPlugin;