Skip to content

Commit

Permalink
fix: 项目先 run 起来
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxingzhe committed Mar 16, 2021
1 parent d58201f commit aef3b2f
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 3,520 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ wepack 借助 [fre](https://github.com/yisar/fre) 实现组件化的支持,借
### Use

```shell

npm link
wepack -e app.js -o /dist/

npm init wepack

npm start
```

- 如果 npm start 遇到 `Cannot read property 'hash' of undefined` 的报错,可以先把 'core/assets/wxss.js' 里的 `data-w-${wxml.hash.slice(0, 6)}` 先改成 `data-w-${wxml ? wxml.hash.slice(0, 6) : ""}`

This comment has been minimized.

Copy link
@yisar

yisar Mar 16, 2021

提一下这个 pr 吧,阿里嘎多

- 如果小程序工具导入 dist 目录,遇到 dist 缺少 app.json 和 sitemap.json 的报错,先手动将 demo 里的这两个文件拷贝到 dist 下,能跑起来再说。

剩下的只需要按照 [微信小程序开发文档](https://developers.weixin.qq.com/miniprogram/dev/framework/) 开发即可

值得注意的是,并非所有的微信小程序的特性都被支持,简单地说,wepack 只支持“现代特性”
Expand Down
55 changes: 29 additions & 26 deletions core/assets/wxss.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const Asset = require("./asset")
const postcss = require("postcss")
const postcssTagReplacer = require("../plugins/postcss-tag-replacer")
const postcssRpx2rem = require("../plugins/postcss-rpx2rem")
const postcssSopedCss = require('../plugins/postcss-scoped-css')
const Path = require('path')
const Asset = require("./asset");
const postcss = require("postcss");
const postcssTagReplacer = require("../plugins/postcss-tag-replacer");
const postcssRpx2rem = require("../plugins/postcss-rpx2rem");
const postcssSopedCss = require("../plugins/postcss-scoped-css");
const Path = require("path");

module.exports = class WxssAsset extends Asset {
constructor(path, type, name) {
super(path, type, name)
super(path, type, name);
}
async parse(input) {
this.input = input
this.input = input;
}
async generate() {
const wxml = this.getWxml(this)
const wxml = this.getWxml(this);
console.log("...wxml", wxml);
this.code = postcss([
postcssTagReplacer({
// css 需要替换的标签
Expand All @@ -26,30 +27,32 @@ module.exports = class WxssAsset extends Asset {
},
}),
postcssSopedCss({
id: `data-w-${wxml.hash.slice(0, 6)}`
id: `data-w-${wxml ? wxml.hash.slice(0, 6) : ""}`,
}),
postcssRpx2rem(),
]).process(this.input).css
]).process(this.input).css;
}
getWxml(asset) {
if (asset.parent.type === 'json') {
const dep = Array.from(asset.parent.dependencies).find(d => d.type === 'wxml')
return asset.parent.depsAssets.get(dep)
if (asset.parent.type === "json") {
const dep = Array.from(asset.parent.dependencies).find(
(d) => d.type === "wxml"
);
return asset.parent.depsAssets.get(dep);
} else {
let p = asset.parent
let i = 0
while (p.type !== 'json') {
p = p.parent
i++
let p = asset.parent;
let i = 0;
while (p.type !== "json") {
p = p.parent;
i++;
}
let a = p
let a = p;
while (i > 0) {
const pw = Array.from(a.dependencies).find(d => d.type === 'wxml')
a = a.depsAssets.get(pw)
i--
const pw = Array.from(a.dependencies).find((d) => d.type === "wxml");
a = a.depsAssets.get(pw);
i--;
}
const o = Array.from(a.dependencies).find(d => d.tag === asset.tag)
return a.depsAssets.get(o)
const o = Array.from(a.dependencies).find((d) => d.tag === asset.tag);
return a.depsAssets.get(o);
}
}
}
};
Empty file modified core/cli.js
100644 → 100755
Empty file.
97 changes: 0 additions & 97 deletions dist/93b885adfe0da089.js

This file was deleted.

22 changes: 0 additions & 22 deletions dist/93b885adfe0da089cdf634904fd59f71.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
.list-items[data-w-5e732a] {
display: flex;
padding: 0 0.3rem;
justify-content: space-around;
align-items: center;
height: 1rem;
font-size: 0.4rem;
border-bottom: 1px solid #e6e6e6;
}
.selectAll[data-w-5e732a] {
width: 0.5rem;
height: 0.5rem;
}
.list-items[data-w-5e732a] input {
flex: auto;
margin-left: 0.3rem;
}
.completed[data-w-5e732a] {
text-decoration: line-through;
color: #d9d9d9;
}

.container[data-w-866668]{
text-align: center;
padding:0.4rem;
Expand Down
20 changes: 1 addition & 19 deletions dist/93b885adfe0da089cdf634904fd59f71.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,4 @@ Page({
this.data.leftcount = this.data.list.filter(item => !item.completed).length;
}

});
Component({
properties: {
item: {
type: Object,
value: {}
}
},
methods: {
clickIco(e) {
this.triggerEvent('myevent', e);
},

clear(e) {
this.triggerEvent('clear', e);
}

}
}, "use-item");
});
6 changes: 3 additions & 3 deletions dist/93b885adfe0da089cdf634904fd59f71.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ remotes['UseItem'] = props => {
} = useComponent(fre.useState({})[1], props, 'use-item');
return fre.h(fre.Fragment, null, fre.h(remotes.View, null, fre.h(remotes.View, {
class: "list-items",
"data-w-5e732a": true
"data-w-e2ba90": true
}, fre.h(remotes.Icon, {
type: item.completed ? 'success' : 'circle',
onClick: e => clickIco(e),
Expand All @@ -74,7 +74,7 @@ remotes['UseItem'] = props => {
onKeyDown: e => edittodo(e),
"data-id": item.id,
value: item.name,
"data-w-5e732a": true
"data-w-e2ba90": true
}), fre.h(remotes.Icon, {
type: "clear",
onClick: e => clear(e)
Expand Down Expand Up @@ -102,7 +102,7 @@ remotes['$3$template$footer'] = props => {
};


window['berial-cditai'] = {
window['berial-ertzhi'] = {
async bootstrap({host}){
const div = document.createElement('div');
div.id = "root";
Expand Down
14 changes: 14 additions & 0 deletions dist/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "todomvc",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light",
"enablePullDownRefresh": true
},
"sitemapLocation": "sitemap.json"
}
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<script src="./app.js"></script>
</head>
<body>
<berial-cditai></berial-cditai>
<berial-ertzhi></berial-ertzhi>
<script>
goober.setup(fre.h);
berial.register([{"name":"berial-cditai","scripts":["/93b885adfe0da089cdf634904fd59f71.js","/93b885adfe0da089cdf634904fd59f71.jsx"],"styles":["/93b885adfe0da089cdf634904fd59f71.css"],"path":"/pages/index/index"}])
berial.register([{"name":"berial-ertzhi","scripts":["/93b885adfe0da089cdf634904fd59f71.js","/93b885adfe0da089cdf634904fd59f71.jsx"],"styles":["/93b885adfe0da089cdf634904fd59f71.css"],"path":"/pages/index/index"}])
</script>

</body>
Expand Down
66 changes: 66 additions & 0 deletions dist/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// pages/index/index.js
Page({

/**
* 页面的初始数据
*/
data: {

},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

}
})
3 changes: 3 additions & 0 deletions dist/pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
2 changes: 2 additions & 0 deletions dist/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!--pages/index/index.wxml-->
<text>xxxxx</text>
1 change: 1 addition & 0 deletions dist/pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* pages/index/index.wxss */

0 comments on commit aef3b2f

Please sign in to comment.