From 24dc56d32817bf2172bf14cd53f1916a3658fed1 Mon Sep 17 00:00:00 2001 From: Malash Date: Tue, 10 Oct 2023 18:13:06 +0800 Subject: [PATCH] add support for Red Mini Program --- packages/cli/src/argv.ts | 13 +++- packages/cli/src/config/webpack.config.ts | 1 + packages/core/src/constants.ts | 2 +- .../templates/src/project.red.json | 69 +++++++++++++++++++ .../demo-todomvc-linaria/src/project.red.json | 69 +++++++++++++++++++ packages/demo-todomvc/src/project.red.json | 69 +++++++++++++++++++ .../webpack-plugin/src/constants/features.ts | 5 +- .../src/plugins/projectConfig.ts | 7 ++ .../src/plugins/shim/variable.ts | 1 + .../webpack-plugin/src/utils/render/index.ts | 9 +++ .../src/utils/transformExtension.ts | 9 +++ 11 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 packages/create-goji-app/templates/src/project.red.json create mode 100644 packages/demo-todomvc-linaria/src/project.red.json create mode 100644 packages/demo-todomvc/src/project.red.json diff --git a/packages/cli/src/argv.ts b/packages/cli/src/argv.ts index cc75234c..747a08f0 100644 --- a/packages/cli/src/argv.ts +++ b/packages/cli/src/argv.ts @@ -8,9 +8,18 @@ export interface CliConfig { progress?: boolean; } -const GOJI_TARGETS: Array = ['wechat', 'baidu', 'alipay', 'toutiao', 'qq', 'toutiao']; +const GOJI_TARGETS: Array = [ + 'wechat', + 'baidu', + 'alipay', + 'toutiao', + 'qq', + 'toutiao', + 'red', +]; -export const parseArgv = (arg: Array) => new Promise((resolve, reject) => { +export const parseArgv = (arg: Array) => + new Promise((resolve, reject) => { const yargsConfig = yargs .command({ command: 'start [target]', diff --git a/packages/cli/src/config/webpack.config.ts b/packages/cli/src/config/webpack.config.ts index 81530590..95985596 100644 --- a/packages/cli/src/config/webpack.config.ts +++ b/packages/cli/src/config/webpack.config.ts @@ -61,6 +61,7 @@ export const getWebpackConfig = ({ baidu: 'css', alipay: 'acss', toutiao: 'ttss', + red: 'css', }; return { diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index e9aa3ccd..b07ee079 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -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; diff --git a/packages/create-goji-app/templates/src/project.red.json b/packages/create-goji-app/templates/src/project.red.json new file mode 100644 index 00000000..b73ee258 --- /dev/null +++ b/packages/create-goji-app/templates/src/project.red.json @@ -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": "." +} diff --git a/packages/demo-todomvc-linaria/src/project.red.json b/packages/demo-todomvc-linaria/src/project.red.json new file mode 100644 index 00000000..b73ee258 --- /dev/null +++ b/packages/demo-todomvc-linaria/src/project.red.json @@ -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": "." +} diff --git a/packages/demo-todomvc/src/project.red.json b/packages/demo-todomvc/src/project.red.json new file mode 100644 index 00000000..b73ee258 --- /dev/null +++ b/packages/demo-todomvc/src/project.red.json @@ -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": "." +} diff --git a/packages/webpack-plugin/src/constants/features.ts b/packages/webpack-plugin/src/constants/features.ts index d79bf18a..a2759139 100644 --- a/packages/webpack-plugin/src/constants/features.ts +++ b/packages/webpack-plugin/src/constants/features.ts @@ -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 @@ -11,7 +11,8 @@ 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 in