uni.compiler.js 5.9 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');
6
var compilerCore = require('@vue/compiler-core');
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

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
var uniad_app_json = function (appJson) {
  if (!appJson.plugins) {
    appJson.plugins = {};
  }
  if (!appJson.plugins['uni-ad']) {
    appJson.plugins['uni-ad'] = {
      version: '1.0.3',
      provider: 'wx999bf02c8e05dfc9',
    };
  }
  if (!appJson.plugins['coral-adv']) {
    appJson.plugins['coral-adv'] = {
      version: '1.0.7',
      provider: 'wx0e203209e27b1e66',
    };
  }

  if (!appJson.usingComponents) {
    appJson.usingComponents = {};
  }
  if (!appJson.usingComponents['uniad-plugin']) {
    appJson.usingComponents['uniad-plugin'] = 'plugin://uni-ad/ad';
  }
};

var uniadAppJson = uniad_app_json;

fxy060608's avatar
fxy060608 已提交
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
const AD_COMPONENTS = [
    'uniad',
    'ad-rewarded-video',
    'ad-fullscreen-video',
    'ad-interstitial',
];
let appJsonUniadFlag = false;
function transformAd(node, context) {
    if (!uniCliShared.isElementNode(node)) {
        return;
    }
    const adpidProp = compilerCore.findProp(node, 'adpid');
    if (node.tag === 'ad' && adpidProp) {
        node.tag = 'uniad';
        node.tagType = 1 /* COMPONENT */;
    }
    if (appJsonUniadFlag) {
        return;
    }
    if (AD_COMPONENTS.indexOf(node.tag) > -1) {
        appJsonUniadFlag = true;
        uniadAppJson(uniCliShared.findJsonFile('app'));
    }
}

fxy060608's avatar
fxy060608 已提交
65 66 67 68 69 70
var description = "项目配置文件。";
var packOptions = {
	ignore: [
	]
};
var setting = {
fxy060608's avatar
fxy060608 已提交
71
	urlCheck: false,
fxy060608's avatar
fxy060608 已提交
72
	es6: true,
fxy060608's avatar
fxy060608 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 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
	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
};

114 115 116 117 118 119
const customElements = [
    'page-container',
    'page-meta',
    'navigation-bar',
    'match-media',
];
fxy060608's avatar
fxy060608 已提交
120
const compilerOptions = {
121
    nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink, transformAd],
fxy060608's avatar
fxy060608 已提交
122
};
123
const COMPONENTS_DIR = 'wxcomponents';
fxy060608's avatar
fxy060608 已提交
124 125 126 127 128
const miniProgram = {
    class: {
        array: true,
    },
    slot: {
129 130
        fallbackContent: false,
        dynamicSlotNames: true,
fxy060608's avatar
fxy060608 已提交
131
    },
132 133 134
    event: {
        key: true,
    },
fxy060608's avatar
fxy060608 已提交
135
    directive: 'wx:',
fxy060608's avatar
fxy060608 已提交
136
    lazyElement: {
137 138 139 140 141 142 143 144 145 146 147 148 149
        canvas: [
            { name: 'bind', arg: ['canvas-id', 'id'] },
            {
                name: 'on',
                arg: ['touchstart', 'touchmove', 'touchcancel', 'touchend'],
            },
        ],
        editor: [
            {
                name: 'on',
                arg: ['ready'],
            },
        ],
150 151
        // iOS 平台需要延迟
        textarea: [{ name: 'on', arg: ['input'] }],
fxy060608's avatar
fxy060608 已提交
152
    },
fxy060608's avatar
fxy060608 已提交
153
    component: {
154
        dir: COMPONENTS_DIR,
fxy060608's avatar
fxy060608 已提交
155
        vShow: uniCliShared.COMPONENT_CUSTOM_HIDDEN,
156 157
        getPropertySync: false,
        normalizeName: (name) => name.startsWith('wx-') ? name.replace('wx-', 'weixin-') : name,
fxy060608's avatar
fxy060608 已提交
158
    },
fxy060608's avatar
fxy060608 已提交
159
};
fxy060608's avatar
fxy060608 已提交
160
const projectConfigFilename = 'project.config.json';
fxy060608's avatar
fxy060608 已提交
161
const options = {
fxy060608's avatar
fxy060608 已提交
162
    cdn: 1,
fxy060608's avatar
fxy060608 已提交
163
    vite: {
fxy060608's avatar
fxy060608 已提交
164
        inject: {
fxy060608's avatar
fxy060608 已提交
165
            uni: [path__default["default"].resolve(__dirname, 'uni.api.esm.js'), 'default'],
fxy060608's avatar
fxy060608 已提交
166
        },
fxy060608's avatar
fxy060608 已提交
167
        alias: {
fxy060608's avatar
fxy060608 已提交
168
            'uni-mp-runtime': path__default["default"].resolve(__dirname, 'uni.mp.esm.js'),
fxy060608's avatar
fxy060608 已提交
169
        },
fxy060608's avatar
fxy060608 已提交
170
        copyOptions: {
171
            assets: [COMPONENTS_DIR],
fxy060608's avatar
fxy060608 已提交
172
            targets: [
fxy060608's avatar
fxy060608 已提交
173
                ...(process.env.UNI_MP_PLUGIN ? [uniCliShared.copyMiniProgramPluginJson] : []),
fxy060608's avatar
fxy060608 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
                {
                    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 已提交
189 190 191 192 193
    },
    global: 'wx',
    app: {
        darkmode: true,
        subpackages: true,
fxy060608's avatar
fxy060608 已提交
194
        plugins: true,
fxy060608's avatar
fxy060608 已提交
195
        usingComponents: true,
fxy060608's avatar
fxy060608 已提交
196 197
    },
    project: {
fxy060608's avatar
fxy060608 已提交
198
        filename: projectConfigFilename,
fxy060608's avatar
fxy060608 已提交
199
        config: ['project.wx.json', 'project.config.json'],
fxy060608's avatar
fxy060608 已提交
200
        source,
fxy060608's avatar
fxy060608 已提交
201
    },
fxy060608's avatar
fxy060608 已提交
202
    template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
fxy060608's avatar
fxy060608 已提交
203
            extname: '.wxs',
fxy060608's avatar
fxy060608 已提交
204
            lang: 'wxs',
fxy060608's avatar
fxy060608 已提交
205 206 207
            generate(filter, filename) {
                if (filename) {
                    return `<wxs src="${filename}.wxs" module="${filter.name}"/>`;
fxy060608's avatar
fxy060608 已提交
208 209 210 211 212
                }
                return `<wxs module="${filter.name}">
${filter.code}
</wxs>`;
            },
fxy060608's avatar
fxy060608 已提交
213
        }, extname: '.wxml', compilerOptions }),
fxy060608's avatar
fxy060608 已提交
214 215 216
    style: {
        extname: '.wxss',
    },
fxy060608's avatar
fxy060608 已提交
217 218 219
};

const uniMiniProgramWeixinPlugin = {
fxy060608's avatar
fxy060608 已提交
220
    name: 'uni:mp-weixin',
fxy060608's avatar
fxy060608 已提交
221 222 223 224 225 226 227
    config() {
        return {
            define: {
                __VUE_CREATED_DEFERRED__: false,
            },
            build: {
                // css 中不支持引用本地资源
fxy060608's avatar
fxy060608 已提交
228
                assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
fxy060608's avatar
fxy060608 已提交
229 230 231
            },
        };
    },
fxy060608's avatar
fxy060608 已提交
232 233
};
var index = [uniMiniProgramWeixinPlugin, ...initMiniProgramPlugin__default["default"](options)];
fxy060608's avatar
fxy060608 已提交
234 235

module.exports = index;