Skip to content

Commit

Permalink
add support for Red Mini Program
Browse files Browse the repository at this point in the history
  • Loading branch information
malash committed Oct 25, 2023
1 parent 3833737 commit dc8bb75
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/cli/src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ export interface CliConfig {
progress?: boolean;
}

const GOJI_TARGETS: Array<GojiTarget> = ['wechat', 'baidu', 'alipay', 'toutiao', 'qq', 'toutiao'];
const GOJI_TARGETS: Array<GojiTarget> = [
'wechat',
'baidu',
'alipay',
'toutiao',
'qq',
'toutiao',
'red',
];

export const parseArgv = (arg: Array<string>) => new Promise<CliConfig>((resolve, reject) => {
export const parseArgv = (arg: Array<string>) =>
new Promise<CliConfig>((resolve, reject) => {
const yargsConfig = yargs
.command({
command: 'start [target]',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/config/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const getWebpackConfig = ({
baidu: 'css',
alipay: 'acss',
toutiao: 'ttss',
red: 'css',
};

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 type GojiTarget = 'wechat' | 'baidu' | 'alipay' | 'toutiao' | 'qq' | 'red';

export interface SimplifyComponent {
name: string;
Expand Down
69 changes: 69 additions & 0 deletions packages/create-goji-app/templates/src/project.red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "3.67.2",
"projectname": "demo",
"debugOptions": {
"hidedInDevtools": []
},
"appid": "testappid",
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
},
"miniprogramRoot": "."
}
69 changes: 69 additions & 0 deletions packages/demo-todomvc-linaria/src/project.red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "3.67.2",
"projectname": "demo",
"debugOptions": {
"hidedInDevtools": []
},
"appid": "testappid",
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
},
"miniprogramRoot": "."
}
69 changes: 69 additions & 0 deletions packages/demo-todomvc/src/project.red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "3.67.2",
"projectname": "demo",
"debugOptions": {
"hidedInDevtools": []
},
"appid": "testappid",
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
},
"miniprogramRoot": "."
}
7 changes: 4 additions & 3 deletions packages/webpack-plugin/src/constants/features.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GojiTarget } from '@goji/core';

export const getFeatures = (target: GojiTarget) => ({
useSubtree: target === 'wechat' || target === 'qq',
useSubtree: target === 'wechat' || target === 'qq' || target === 'red',

useInlineChildrenInComponent:
// Alipay only support circular dependency self to self so we have to inline the children.wxml
Expand All @@ -11,12 +11,13 @@ export const getFeatures = (target: GojiTarget) => ({
// Baidu changes the behavior of circular dependency on dev tool >= v4.22 with new compiler
// so we have to inline the children.wxml
// https://smartprogram.baidu.com/docs/develop/devtools/beta-notify#_5-%E6%A8%A1%E6%9D%BF-import-%E8%AF%AD%E6%B3%95%E4%B8%8D%E5%85%81%E8%AE%B8%E5%BE%AA%E7%8E%AF%E5%BC%95%E7%94%A8%E3%80%82
target === 'baidu',
target === 'baidu' ||
target === 'red',

// Alipay doesn't support <include> in <template> if Lib v2.0 is enabled.
// Unfortunately, it has been forced to enable since mid-year 2023.
// https://github.com/airbnb/goji-js/issues/140
useInlineLeafComponents: target === 'alipay',
useInlineLeafComponents: target === 'alipay' || target === 'red',

// Baidu fails to render if an outside same `<include>` exists
// https://github.com/airbnb/goji-js/issues/185
Expand Down
7 changes: 7 additions & 0 deletions packages/webpack-plugin/src/plugins/projectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export class GojiProjectConfigPlugin extends GojiBasedWebpackPlugin {
});
}

if (target === 'red') {
patterns.push({
from: 'project.red.json',
to: 'project.config.json',
});
}

if (patterns.length) {
new CopyWebpackPlugin({
patterns: patterns.map(pattern => ({ ...pattern, noErrorOnMissing: true })),
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-plugin/src/plugins/shim/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const API_VARIABLE_NAME: Record<GojiTarget, string> = {
alipay: 'my',
qq: 'qq',
toutiao: 'tt',
red: 'xhs',
};

export const getApiVariableDefinitions = (target: GojiTarget) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/webpack-plugin/src/utils/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export const transformTemplate = async (
default:
return source;
}
case 'red':
switch (type) {
case 'wxml':
return source.replace(/wx:/g, 'xhs:').replace(/\.wxml/g, '.xhsml');
case 'js':
return source;
default:
return source;
}
default:
return source;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/webpack-plugin/src/utils/transformExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const transformExtension = ({
default:
return extension;
}
case 'red':
switch (extension) {
case '.wxml':
return '.xhsml';
case '.wxss':
return '.css';
default:
return extension;
}
default:
return extension;
}
Expand Down

0 comments on commit dc8bb75

Please sign in to comment.