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

fxy060608's avatar
fxy060608 已提交
3
var uniCliShared = require('@dcloudio/uni-cli-shared');
fxy060608's avatar
fxy060608 已提交
4
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
fxy060608's avatar
fxy060608 已提交
5
var path = require('path');
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
var description = "项目配置文件。";
var packOptions = {
	ignore: [
	]
};
var setting = {
fxy060608's avatar
fxy060608 已提交
18
	urlCheck: false,
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
	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
};

61 62 63 64 65 66
const customElements = [
    'page-container',
    'page-meta',
    'navigation-bar',
    'match-media',
];
fxy060608's avatar
fxy060608 已提交
67 68 69
const compilerOptions = {
    nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink],
};
70
const COMPONENTS_DIR = 'wxcomponents';
fxy060608's avatar
fxy060608 已提交
71 72 73 74 75
const miniProgram = {
    class: {
        array: true,
    },
    slot: {
76 77
        fallbackContent: false,
        dynamicSlotNames: true,
fxy060608's avatar
fxy060608 已提交
78 79
    },
    directive: 'wx:',
fxy060608's avatar
fxy060608 已提交
80
    lazyElement: {
fxy060608's avatar
fxy060608 已提交
81 82
        canvas: [{ name: 'bind', arg: ['canvas-id', 'id'] }],
        editor: [{ name: 'on', arg: ['ready'] }],
83 84
        // iOS 平台需要延迟
        textarea: [{ name: 'on', arg: ['input'] }],
fxy060608's avatar
fxy060608 已提交
85
    },
fxy060608's avatar
fxy060608 已提交
86
    component: {
87
        dir: COMPONENTS_DIR,
fxy060608's avatar
fxy060608 已提交
88
        vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN,
fxy060608's avatar
fxy060608 已提交
89
        getPropertySync: false, // 为了避免 Setting data field "uP" to undefined is invalid 警告
fxy060608's avatar
fxy060608 已提交
90
    },
fxy060608's avatar
fxy060608 已提交
91
};
fxy060608's avatar
fxy060608 已提交
92
const projectConfigFilename = 'project.config.json';
fxy060608's avatar
fxy060608 已提交
93
const options = {
fxy060608's avatar
fxy060608 已提交
94
    cdn: 1,
fxy060608's avatar
fxy060608 已提交
95
    vite: {
fxy060608's avatar
fxy060608 已提交
96
        inject: {
fxy060608's avatar
fxy060608 已提交
97
            uni: [path__default["default"].resolve(__dirname, 'uni.api.esm.js'), 'default'],
fxy060608's avatar
fxy060608 已提交
98
        },
fxy060608's avatar
fxy060608 已提交
99
        alias: {
fxy060608's avatar
fxy060608 已提交
100
            'uni-mp-runtime': path__default["default"].resolve(__dirname, 'uni.mp.esm.js'),
fxy060608's avatar
fxy060608 已提交
101
        },
fxy060608's avatar
fxy060608 已提交
102
        copyOptions: {
103
            assets: [COMPONENTS_DIR],
fxy060608's avatar
fxy060608 已提交
104
            targets: [
fxy060608's avatar
fxy060608 已提交
105
                ...(process.env.UNI_MP_PLUGIN ? [uniCliShared.copyMiniProgramPluginJson] : []),
fxy060608's avatar
fxy060608 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
                {
                    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 已提交
121 122 123 124 125
    },
    global: 'wx',
    app: {
        darkmode: true,
        subpackages: true,
fxy060608's avatar
fxy060608 已提交
126
        plugins: true,
fxy060608's avatar
fxy060608 已提交
127 128
    },
    project: {
fxy060608's avatar
fxy060608 已提交
129 130
        filename: projectConfigFilename,
        source,
fxy060608's avatar
fxy060608 已提交
131
    },
fxy060608's avatar
fxy060608 已提交
132
    template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
fxy060608's avatar
fxy060608 已提交
133
            extname: '.wxs',
fxy060608's avatar
fxy060608 已提交
134
            lang: 'wxs',
fxy060608's avatar
fxy060608 已提交
135 136 137
            generate(filter, filename) {
                if (filename) {
                    return `<wxs src="${filename}.wxs" module="${filter.name}"/>`;
fxy060608's avatar
fxy060608 已提交
138 139 140 141 142
                }
                return `<wxs module="${filter.name}">
${filter.code}
</wxs>`;
            },
fxy060608's avatar
fxy060608 已提交
143
        }, extname: '.wxml', compilerOptions }),
fxy060608's avatar
fxy060608 已提交
144 145 146
    style: {
        extname: '.wxss',
    },
fxy060608's avatar
fxy060608 已提交
147 148 149 150 151 152 153 154 155 156 157
};

const uniMiniProgramWeixinPlugin = {
    name: 'vite:uni-mp-weixin',
    config() {
        return {
            define: {
                __VUE_CREATED_DEFERRED__: false,
            },
            build: {
                // css 中不支持引用本地资源
fxy060608's avatar
fxy060608 已提交
158
                assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
fxy060608's avatar
fxy060608 已提交
159 160 161
            },
        };
    },
fxy060608's avatar
fxy060608 已提交
162 163
};
var index = [uniMiniProgramWeixinPlugin, ...initMiniProgramPlugin__default["default"](options)];
fxy060608's avatar
fxy060608 已提交
164 165

module.exports = index;