-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathconstants.ts
54 lines (49 loc) · 1.74 KB
/
constants.ts
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
export const GOJI_VIRTUAL_ROOT = 'GOJI_VIRTUAL_ROOT';
export const TYPE_TEXT = 'GOJI_TYPE_TEXT';
export const TYPE_SUBTREE = 'GOJI_TYPE_SUBTREE';
export type GojiTarget = 'wechat' | 'baidu' | 'alipay' | 'toutiao' | 'qq' | 'toutiao';
export const GOJI_TARGET: GojiTarget = (process.env.GOJI_TARGET as GojiTarget) || 'wechat';
export interface SimplifyComponent {
name: string;
properties: Array<string>;
events: Array<string>;
}
export const SIMPLIFY_COMPONENTS: Array<SimplifyComponent> = [
{
name: 'view',
properties: ['className', 'style'],
events: [],
},
];
/**
* Get identifiers used by template. For production we use shorter identifiers for less bundle size.
* This function is shared by both `@goji/core` and `@goji/webpack-plugin`.
*
* meta: for element data source, e.g. `<template data="{{ meta: meta }}" />`
* props: for element props object, e.g. `<input value="{{meta.props.value}}" />`
* type: for element type, e.g. `<input wx:if="{{meta.type === 'input'}}" />`
* text: for text element content, e.g. `<text>{{meta.text}}</text>`
* children: for element's children, e.g. `<block wx:for="{{meta.children}}" />`
* gojiId: for element Goji id, which is the unique id for each element, e.g. <view data-goji-id="{{meta.gojiId}}">
* simplifiedId: for element simplified id
*/
export const getTemplateIds = (nodeEnv = process.env.NODE_ENV) =>
nodeEnv === 'production'
? {
meta: 'm',
props: 'p',
type: 't',
text: 'x',
children: 'c',
gojiId: 'g',
simplifiedId: 's',
}
: {
meta: 'meta',
props: 'props',
type: 'type',
text: 'text',
children: 'children',
gojiId: 'gojiId',
simplifiedId: 'simplifiedId',
};