Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat: 支持buildMiniComponent,以webpack方式构建小程序自定义组件
Browse files Browse the repository at this point in the history
  • Loading branch information
sydeEvans committed Jul 27, 2021
1 parent 90fddc4 commit e5ed805
Show file tree
Hide file tree
Showing 62 changed files with 9,948 additions and 5 deletions.
12 changes: 12 additions & 0 deletions e2e/mini/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dist/
yarn-error.log
yarn.lock
.tea
.vscode
.DS_Store
!src/node_modules
build/
miniapptools_dist/

alipay/components
wechat/components
3 changes: 3 additions & 0 deletions e2e/mini/alipay/app.acss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
page {
background: #f7f7f7;
}
11 changes: 11 additions & 0 deletions e2e/mini/alipay/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
App({
onLaunch(options) {
// 第一次打开
// options.query == {number:1}
console.info('App onLaunch');
},
onShow(options) {
// 从后台被 scheme 重新打开
// options.query == {number:1}
},
});
8 changes: 8 additions & 0 deletions e2e/mini/alipay/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"pages": [
"pages/index/index"
],
"window": {
"defaultTitle": "My App"
}
}
5 changes: 5 additions & 0 deletions e2e/mini/alipay/mini.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exclude": [
"dist/**/*"
]
}
1 change: 1 addition & 0 deletions e2e/mini/alipay/pages/index/index.acss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* required by usingComponents */
6 changes: 6 additions & 0 deletions e2e/mini/alipay/pages/index/index.axml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<view>
this is a blank page
<greet name="greet1"></greet>
<greet2 name="greet2"></greet2>
</view>
35 changes: 35 additions & 0 deletions e2e/mini/alipay/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Page({
onLoad(query) {
// 页面加载
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
},
onReady() {
// 页面加载完成
},
onShow() {
// 页面显示
},
onHide() {
// 页面隐藏
},
onUnload() {
// 页面被关闭
},
onTitleClick() {
// 标题被点击
},
onPullDownRefresh() {
// 页面被下拉
},
onReachBottom() {
// 页面被拉到底部
},
onShareAppMessage() {
// 返回自定义分享信息
return {
title: 'My App',
desc: 'My App description',
path: 'pages/index/index',
};
},
});
6 changes: 6 additions & 0 deletions e2e/mini/alipay/pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"usingComponents": {
"greet": "/components/greet/index",
"greet2": "/components/greet2/index"
}
}
30 changes: 30 additions & 0 deletions e2e/mini/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { buildMiniComponent } = require('@remax/cli');

const buildMap = [
{
target: 'ali',
output: 'alipay/components',
rootDir: 'src',
pxToRpx: true,
input: {
greet: 'greet/index',
greet2: 'greet2/index',
},
},
{
target: 'wechat',
output: 'wechat/components',
rootDir: 'src',
pxToRpx: true,
input: {
greet: 'greet/index',
},
},
];

buildMap.forEach(it => {
buildMiniComponent({
cwd: process.cwd(),
...it,
});
});
19 changes: 19 additions & 0 deletions e2e/mini/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "e2e-mini",
"private": true,
"version": "1.0.0",
"scripts": {
"build": "node build.js"
},
"dependencies": {
"mini-antui": "^0.4.34",
"react": "^16.8.6",
"remax": "*"
},
"workspaces": {
"nohoist": [
"mini-antui",
"react"
]
}
}
11 changes: 11 additions & 0 deletions e2e/mini/src/greet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { View } from 'remax/one';

console.log('greeting1');
export default ({ name }) => {
return (
<View id="greeting">
<View>Hello {name}</View>
</View>
);
};
15 changes: 15 additions & 0 deletions e2e/mini/src/greet2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';
import { View } from 'remax/one';
import Badge from 'mini-antui/es/badge';

console.log('greeting2');
export default ({ name }) => {
return (
<View id="greeting">
<View>Hello {name}</View>
<Badge>
<View slot="inner">Remax</View>
</Badge>
</View>
);
};
19 changes: 19 additions & 0 deletions e2e/mini/wechat/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// app.js
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || [];
logs.unshift(Date.now());
wx.setStorageSync('logs', logs);

// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
},
});
},
globalData: {
userInfo: null,
},
});
13 changes: 13 additions & 0 deletions e2e/mini/wechat/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pages":[
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
10 changes: 10 additions & 0 deletions e2e/mini/wechat/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
48 changes: 48 additions & 0 deletions e2e/mini/wechat/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// index.js
// 获取应用实例
const app = getApp();

Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs',
});
},
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true,
});
}
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: res => {
console.log(res);
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
});
},
});
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log(e);
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true,
});
},
});
5 changes: 5 additions & 0 deletions e2e/mini/wechat/pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"usingComponents": {
"greet": "/components/greet/index"
}
}
5 changes: 5 additions & 0 deletions e2e/mini/wechat/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--index.wxml-->
<view class="container">
hello remax
<greet name="hello"/>
</view>
19 changes: 19 additions & 0 deletions e2e/mini/wechat/pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
color: #aaa;
}

.userinfo-avatar {
overflow: hidden;
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}

.usermotto {
margin-top: 200px;
}
68 changes: 68 additions & 0 deletions e2e/mini/wechat/project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"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": "2.18.1",
"appid": "wx4f97573c7eadf58f",
"projectname": "wechat",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
7 changes: 7 additions & 0 deletions e2e/mini/wechat/sitemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
Loading

0 comments on commit e5ed805

Please sign in to comment.