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

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

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

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

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

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

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

module.exports = index;