uni.compiler.js 4.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
'use strict';

var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var fs = require('fs-extra');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefaultLegacy(initMiniProgramPlugin);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

var description = "项目配置文件。";
var packOptions = {
	ignore: [
	]
};
var setting = {
	urlCheck: true,
	es6: true,
	postcss: false,
	minified: false,
	newFeature: true,
	nodeModules: false
};
var compileType = "miniprogram";
var libVersion = "";
var appid = "touristappid";
var projectname = "";
var condition = {
	search: {
		current: -1,
		list: [
		]
	},
	conversation: {
		current: -1,
		list: [
		]
	},
	game: {
		current: -1,
		list: [
		]
	},
	miniprogram: {
		current: -1,
		list: [
		]
	}
};
var source = {
	description: description,
	packOptions: packOptions,
	setting: setting,
	compileType: compileType,
	libVersion: libVersion,
	appid: appid,
	projectname: projectname,
	condition: condition
};

let isFixed = false;
function fix2648(bundle) {
    if (isFixed) {
        return;
    }
    const appJsonAsset = bundle['app.json'];
    if (!appJsonAsset) {
        return;
    }
    try {
        const { usingComponents } = JSON.parse(appJsonAsset.source.toString());
        if (usingComponents && !Object.keys(usingComponents).length) {
            fs__default["default"].outputFileSync(path__default["default"].resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.json'), `{"component":true}`);
            fs__default["default"].outputFileSync(path__default["default"].resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.qml'), `<!-- https://github.com/dcloudio/uni-app/issues/2648 -->`);
            fs__default["default"].outputFileSync(path__default["default"].resolve(process.env.UNI_OUTPUT_DIR, 'fix-2648.js'), `Component({})`);
        }
        isFixed = true;
    }
    catch (_a) { }
}

fxy060608's avatar
fxy060608 已提交
85
const uniMiniProgramQQPlugin = {
fxy060608's avatar
fxy060608 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    name: 'vite:uni-mp-qq',
    config() {
        return {
            define: {
                __VUE_CREATED_DEFERRED__: false,
            },
        };
    },
    writeBundle(_, bundle) {
        fix2648(bundle);
    },
};
const options = {
    vite: {
        inject: {
            uni: [
                uniCliShared.resolveBuiltIn('@dcloudio/uni-mp-qq/dist/uni.api.esm.js'),
                'default',
            ],
        },
        alias: {
            'uni-mp-runtime': uniCliShared.resolveBuiltIn('@dcloudio/uni-mp-qq/dist/uni.mp.esm.js'),
        },
        copyOptions: {
            assets: ['wxcomponents'],
            targets: [
                {
                    src: ['custom-tab-bar'],
                    get dest() {
                        return process.env.UNI_OUTPUT_DIR;
                    },
                },
            ],
        },
    },
    global: 'qq',
    app: {
fxy060608's avatar
fxy060608 已提交
123
        darkmode: false,
fxy060608's avatar
fxy060608 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        subpackages: true,
    },
    project: {
        filename: 'project.config.json',
        source,
    },
    template: {
        filter: {
            extname: '.qs',
            lang: 'wxs',
            generate(filter, filename) {
                if (filename) {
                    return `<qs src="${filename}.qs" module="${filter.name}"/>`;
                }
                return `<qs module="${filter.name}">
${filter.code}
</qs>`;
            },
        },
        slot: {
            fallback: false,
        },
        extname: '.qml',
        directive: 'qq:',
        compilerOptions: {
            nodeTransforms: [uniCliShared.addComponentBindLink],
        },
    },
    style: {
        extname: '.qss',
    },
};
fxy060608's avatar
fxy060608 已提交
156
var index = [uniMiniProgramQQPlugin, ...initMiniProgramPlugin__default["default"](options)];
fxy060608's avatar
fxy060608 已提交
157 158

module.exports = index;