Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: support harmony #836

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
13 changes: 4 additions & 9 deletions examples/with-rax-mpa/build.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"targets": ["web", "weex", "kraken"],
"weex": {
"targets": ["harmony"],
"harmony": {
"mpa": true
},
"kraken": {
"mpa": true
},
"web": {
"mpa": true
},
"swc": true,
"minify": false,
"compileDependencies": [],
"webpack5": true
}
5 changes: 5 additions & 0 deletions examples/with-rax-mpa/src/app-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
onCreate() {
console.info('app created');
}
}
4 changes: 0 additions & 4 deletions examples/with-rax-mpa/src/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"name": "home",
"source": "pages/Home/index",
"spm": "b456"
},
{
"name": "about",
"source": "pages/About/app"
}
],
"spm": "a123",
Expand Down
8 changes: 2 additions & 6 deletions examples/with-rax-mpa/src/components/Logo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { createElement, PureComponent } from 'rax';
import Image from 'rax-image';

import './index.css';

class Logo extends PureComponent {
render() {
const source = {
uri: `${process.env.PUBLIC_URL}/rax.png`,
};
return (
<Image
<image
className="logo"
source={source}
src={'https://img.alicdn.com/imgextra/i4/O1CN0145ZaIM1QEObAAbKa1_!!6000000001944-2-tps-1701-1535.png'}
/>
);
}
Expand Down
11 changes: 0 additions & 11 deletions examples/with-rax-mpa/src/pages/About/app.json

This file was deleted.

19 changes: 0 additions & 19 deletions examples/with-rax-mpa/src/pages/About/app.ts

This file was deleted.

16 changes: 0 additions & 16 deletions examples/with-rax-mpa/src/pages/About/index.css

This file was deleted.

16 changes: 0 additions & 16 deletions examples/with-rax-mpa/src/pages/About/index.tsx

This file was deleted.

8 changes: 8 additions & 0 deletions examples/with-rax-mpa/src/pages/Home/index.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
.home {
box-sizing: border-box;
display: flex;
flex-direction: column;
flex-shrink: 0;
align-content: flex-start;
align-items: center;
margin-top: 200rpx;
width: 100%;
}

.title {
font-size: 35rpx;
font-weight: bold;
margin: 20rpx 0;
display: block;
}

.info {
font-size: 36rpx;
margin: 8rpx 0;
color: #555;
display: block;
}
12 changes: 5 additions & 7 deletions examples/with-rax-mpa/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { createElement } from 'rax';
import View from 'rax-view';
import Text from 'rax-text';
import Logo from '@/components/Logo';

import './index.css';

export default function Home(props) {
return (
<View className="home">
<Logo />
<Text className="title">Welcome to Your Rax App</Text>
<Text className="info">More information about Rax</Text>
</View>
<div className="home">
<Logo/>
<text className="title">Welcome to Your Rax App</text>
<text className="info">More information about Rax</text>
</div>
);
}
1 change: 1 addition & 0 deletions packages/platform-loader/src/TraverseImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption)
'bytedance-microapp': ['isByteDanceMicroApp'],
'kuaishou-miniprogram': ['isKuaiShouMiniProgram'],
'baidu-smartprogram': ['isBaiduSmartProgram'],
harmony: ['isHarmony'],
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-rax-app/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
SSR: 'ssr',
WEEX: 'weex',
KRAKEN: 'kraken',
HARMONY: 'harmony',
MINIAPP,
WECHAT_MINIPROGRAM,
BYTEDANCE_MICROAPP,
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-rax-app/src/launch/setupBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
WEB,
WEEX,
KRAKEN,
HARMONY,
} from '../constants';

const highlightPrint = chalk.hex('#F4AF3D');
Expand Down Expand Up @@ -74,6 +75,15 @@ export default (api) => {
console.log();
}
});

if (targets.includes(HARMONY)) {
console.log(highlightPrint('[HARMONY] Bundle at:'));
console.log(
' ',
chalk.underline.white(path.resolve(rootDir, outputDir, HARMONY)),
);
console.log();
}
}
});
};
Expand Down
20 changes: 19 additions & 1 deletion packages/plugin-rax-app/src/launch/setupDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chokidar from 'chokidar';
import { platformMap } from 'miniapp-builder-shared';

import logWebpackConfig from '../utils/logWebpackConfig';
import { MINIAPP_PLATFORMS, MINIAPP, WEB, WEEX, KRAKEN, DEV_URL_PREFIX } from '../constants';
import { MINIAPP_PLATFORMS, MINIAPP, WEB, WEEX, KRAKEN, DEV_URL_PREFIX, HARMONY } from '../constants';
import generateTempFile from '../utils/generateTempFile';

const highlightPrint = chalk.hex('#F4AF3D');
Expand All @@ -20,6 +20,7 @@ interface IDevInfo {
weex?: string[];
kraken?: string[];
pha?: string[];
harmony?: string[];
};
compiledTime?: number;
publicPath?: string;
Expand Down Expand Up @@ -51,9 +52,11 @@ export default function (api) {
let webEntryKeys = [];
let weexEntryKeys = [];
let krakenEntryKeys = [];
let harmonyEntryKeys = [];
let webMpa = false;
let weexMpa = false;
let krakenMpa = false;
let harmonyMpa = false;
let isFirstCompile = true;
let pha = false;
watchAppJson(rootDir, log);
Expand All @@ -78,16 +81,19 @@ export default function (api) {
const webWebpackInfo = getWebpackInfo(configs, 'web');
const weexWebpackInfo = getWebpackInfo(configs, 'weex');
const krakenWebpackInfo = getWebpackInfo(configs, 'kraken');
const harmonyWebpackInfo = getWebpackInfo(configs, 'harmony');

devInfo.publicPath = webWebpackInfo.publicPath;

webEntryKeys = Object.keys(webWebpackInfo.entry);
weexEntryKeys = Object.keys(weexWebpackInfo.entry);
krakenEntryKeys = Object.keys(krakenWebpackInfo.entry);
harmonyEntryKeys = Object.keys(harmonyWebpackInfo.entry);

webMpa = userConfig.web && userConfig.web.mpa;
weexMpa = userConfig.weex && userConfig.weex.mpa;
krakenMpa = userConfig.kraken && userConfig.kraken.mpa;
harmonyMpa = userConfig.harmony && userConfig.harmony.mpa;
pha = userConfig.web && userConfig.web.pha;

// Remove outputDir when start devServer
Expand Down Expand Up @@ -212,6 +218,18 @@ export default function (api) {
});
}

if (targets.includes(HARMONY)) {
devInfo.urls.harmony = [];
// Use Weex App to scan ip address (mobile phone can't visit localhost).
console.log(highlightPrint(' [Harmony] Development server at: '));
weexEntryKeys.forEach((entryKey) => {
const harmonyUrl = `${urlPrefix}/harmony/${harmonyMpa ? entryKey : 'index'}.js`;
devInfo.urls.weex.push(harmonyUrl);
console.log(` ${chalk.underline.white(harmonyUrl)}`);
console.log();
});
}

/**
* @TODO: Delete it first, and then open it after the PHA supports it
*/
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-rax-app/src/userConfig/atoms/inlineStyle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { WEB, WEEX, DOCUMENT, SSR, KRAKEN, MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM } = require('../../constants');
const { WEB, WEEX, DOCUMENT, SSR, KRAKEN, MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM, HARMONY } = require('../../constants');
const { createCSSRule } = require('rax-webpack-config');
const { isWebpack4 } = require('@builder/compat-webpack4');
const getPostCssPlugin = require('../../getPostCssPlugin');
Expand All @@ -8,7 +8,9 @@ const webStandardList = [
];

const inlineStandardList = [
WEEX, KRAKEN,
WEEX,
KRAKEN,
HARMONY,
];

const miniappStandardList = [
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-rax-harmony/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

## v1.0.0
31 changes: 31 additions & 0 deletions packages/plugin-rax-harmony/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "build-plugin-rax-harmony",
"version": "1.0.0",
"description": "rax harmony app plugin",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": [
"lib",
"!lib/**/*.map"
],
"keywords": [
"plugin",
"rax"
],
"author": "Rax Team",
"license": "MIT",
"peerDependencies": {
"build-scripts": "^1.0.0",
"rax": "^1.0.0"
},
"dependencies": {
"@builder/mpa-config": "^4.0.0",
"fs-extra": "^9.0.1",
"@builder/app-helpers": "^2.1.0",
"react-dev-utils": "^11.0.0",
"loader-utils": "^2.0.0",
"@builder/compat-webpack4": "^1.0.0"
}
}
17 changes: 17 additions & 0 deletions packages/plugin-rax-harmony/src/BundleShellPlugin/LiteShell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import BaseShell from './Shell';

const requireModuleMethod = `
function requireModule(moduleName) {
return requireNative(moduleName.slice(1));
}
`;

export default class LiteShell extends BaseShell {
generateApp() {
return `${requireModuleMethod}
var options = ${this.content};

new ViewModule(options);
`;
}
}
Loading