uni.compiler.js 3.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3
'use strict';

var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
fxy060608's avatar
fxy060608 已提交
4 5
var path = require('path');
var uniCliShared = require('@dcloudio/uni-cli-shared');
fxy060608's avatar
fxy060608 已提交
6 7 8 9

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

var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefaultLegacy(initMiniProgramPlugin);
fxy060608's avatar
fxy060608 已提交
10
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
fxy060608's avatar
fxy060608 已提交
11

fxy060608's avatar
fxy060608 已提交
12 13 14 15 16 17 18
var description = "项目配置文件。";
var packOptions = {
	ignore: [
	]
};
var setting = {
	urlCheck: true,
fxy060608's avatar
fxy060608 已提交
19
	es6: true,
fxy060608's avatar
fxy060608 已提交
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
	postcss: false,
	minified: false,
	newFeature: true
};
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
};

const projectConfigFilename = 'project.config.json';
fxy060608's avatar
fxy060608 已提交
62 63
const options = {
    vite: {
fxy060608's avatar
fxy060608 已提交
64
        inject: {
fxy060608's avatar
fxy060608 已提交
65
            uni: [path__default["default"].resolve(__dirname, 'uni.api.esm.js'), 'default'],
fxy060608's avatar
fxy060608 已提交
66
        },
fxy060608's avatar
fxy060608 已提交
67
        alias: {
fxy060608's avatar
fxy060608 已提交
68
            'uni-mp-runtime': path__default["default"].resolve(__dirname, 'uni.mp.esm.js'),
fxy060608's avatar
fxy060608 已提交
69
        },
fxy060608's avatar
fxy060608 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        copyOptions: {
            assets: ['wxcomponents'],
            targets: [
                {
                    src: [
                        'theme.json',
                        'sitemap.json',
                        'ext.json',
                        'custom-tab-bar',
                        'functional-pages',
                        projectConfigFilename,
                    ],
                    get dest() {
                        return process.env.UNI_OUTPUT_DIR;
                    },
                },
            ],
        },
fxy060608's avatar
fxy060608 已提交
88 89 90 91 92 93 94
    },
    global: 'wx',
    app: {
        darkmode: true,
        subpackages: true,
    },
    project: {
fxy060608's avatar
fxy060608 已提交
95 96
        filename: projectConfigFilename,
        source,
fxy060608's avatar
fxy060608 已提交
97 98
    },
    template: {
fxy060608's avatar
fxy060608 已提交
99 100 101
        class: {
            array: true,
        },
fxy060608's avatar
fxy060608 已提交
102 103
        filter: {
            extname: '.wxs',
fxy060608's avatar
fxy060608 已提交
104
            lang: 'wxs',
fxy060608's avatar
fxy060608 已提交
105 106 107
            generate(filter, filename) {
                if (filename) {
                    return `<wxs src="${filename}.wxs" module="${filter.name}"/>`;
fxy060608's avatar
fxy060608 已提交
108 109 110 111 112 113
                }
                return `<wxs module="${filter.name}">
${filter.code}
</wxs>`;
            },
        },
fxy060608's avatar
fxy060608 已提交
114 115 116
        slot: {
            fallback: false,
        },
fxy060608's avatar
fxy060608 已提交
117
        extname: '.wxml',
118
        directive: 'wx:',
fxy060608's avatar
fxy060608 已提交
119
        compilerOptions: {
120 121 122
            isCustomElement: (tag) => {
                return ['page-meta', 'navigation-bar', 'match-media'].includes(tag);
            },
fxy060608's avatar
fxy060608 已提交
123 124 125 126
            nodeTransforms: [
                uniCliShared.transformRef,
                uniCliShared.createTransformComponentLink(uniCliShared.COMPONENT_BIND_LINK),
            ],
fxy060608's avatar
fxy060608 已提交
127
        },
fxy060608's avatar
fxy060608 已提交
128 129 130 131
    },
    style: {
        extname: '.wxss',
    },
fxy060608's avatar
fxy060608 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
};

const uniMiniProgramWeixinPlugin = {
    name: 'vite:uni-mp-weixin',
    config() {
        return {
            define: {
                __VUE_CREATED_DEFERRED__: false,
            },
            build: {
                // css 中不支持引用本地资源
                assetsInlineLimit: 40 * 1024, // 40kb
            },
        };
    },
fxy060608's avatar
fxy060608 已提交
147 148
};
var index = [uniMiniProgramWeixinPlugin, ...initMiniProgramPlugin__default["default"](options)];
fxy060608's avatar
fxy060608 已提交
149 150

module.exports = index;