Skip to content

Commit

Permalink
小程序加入分包和组件
Browse files Browse the repository at this point in the history
  • Loading branch information
huangwenming committed May 9, 2018
1 parent 22d9728 commit 29b8fa5
Show file tree
Hide file tree
Showing 40 changed files with 1,051 additions and 7 deletions.
18 changes: 13 additions & 5 deletions micro-app/app.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"pages":[
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/example/example"
],
"window":{
"backgroundTextStyle":"light",
"subPackages": [
{
"root": "packageMore",
"pages": [
"pages/conclude/conclude"
]
}
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
"navigationBarTextStyle": "black"
}
}
}
26 changes: 26 additions & 0 deletions micro-app/components/week/week.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// components/week/week.js
Component({
/**
* 组件的属性列表
*/
properties: {
dateArray: {
type: Array,
value: []
}
},

/**
* 组件的初始数据
*/
data: {
privateData: {}
},

/**
* 组件的方法列表
*/
methods: {

}
})
4 changes: 4 additions & 0 deletions micro-app/components/week/week.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
6 changes: 6 additions & 0 deletions micro-app/components/week/week.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--components/week/week.wxml-->
<view class="date-container">
<div wx:for="{{dateArray}}" class="date-item">
<text class="date-num">week组件{{item.dateNum}}</text>
</div>
</view>
15 changes: 15 additions & 0 deletions micro-app/components/week/week.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* components/week/week.wxss */
.date-container {
height: 50px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.date-item {
flex: 1;
text-align: center;
}
.date-num {
color: forestgreen
}
66 changes: 66 additions & 0 deletions micro-app/packageMore/pages/conclude/conclude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// packageMore/pages/conclude.js
Page({

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

},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log('page conclude in packageMore is loaded')
},

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

},

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

},

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

},

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

},

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

},

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

},

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

}
})
1 change: 1 addition & 0 deletions micro-app/packageMore/pages/conclude/conclude.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 2 additions & 0 deletions micro-app/packageMore/pages/conclude/conclude.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!--packageMore/pages/conclude.wxml-->
<text>packageMore/pages/conclude.wxml</text>
1 change: 1 addition & 0 deletions micro-app/packageMore/pages/conclude/conclude.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* packageMore/pages/conclude.wxss */
13 changes: 12 additions & 1 deletion micro-app/pages/example/example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const app = getApp()
Page({
data: {

dateArray: []
},
onLoad: function () {
console.log('example page loaded');
this.setData({
dateArray: [{ dateNum: 1 }, { dateNum: 2 }, { dateNum: 3 }]
})
},
showShareMenu: function (e) {
wx.showShareMenu({
Expand Down Expand Up @@ -43,4 +49,9 @@ Page({
listenSwiper(e) {
console.log('change swipe')
},
goToConcludePage() {
wx.navigateTo({
url: '/packageMore/pages/conclude/conclude',
})
}
})
6 changes: 5 additions & 1 deletion micro-app/pages/example/example.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"usingComponents": {
"custom-week": "/components/week/week"
}
}
4 changes: 4 additions & 0 deletions micro-app/pages/example/example.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<cover-view class="place_info_order">66666</cover-view>
</cover-view>
</map>
<view><button bindtap='goToConcludePage'>跳转到另外一个包</button></view>
<view>
<custom-week dateArray="{{dateArray}}"></custom-week>
</view>
</scroll-view>
1 change: 1 addition & 0 deletions micro-app/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Page({
})
},
onLoad: function () {
console.log('index page loaded');
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
Expand Down
1 change: 1 addition & 0 deletions micro-app/pages/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<view class='examples'>
<button bindtap='goToExampleList'>示例demos</button>
</view>
<div><p style="color: #f00">hello world</p></div>
</view>
1 change: 1 addition & 0 deletions micro-app/pages/logs/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Page({
logs: []
},
onLoad: function () {
console.log('log page loaded');
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
Expand Down
14 changes: 14 additions & 0 deletions webpack4/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
["env", { "modules": false }],
"stage-2"
],
"plugins": ["transform-runtime"],
"comments": false,
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": [ "istanbul" ]
}
}
}
22 changes: 22 additions & 0 deletions webpack4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vue2

> A Vue.js project
## Build Setup

``` bash
# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

```

For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
41 changes: 41 additions & 0 deletions webpack4/build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'
require('./check-versions')()

process.env.NODE_ENV = 'production'

const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')

const spinner = ora('building for production...')
spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
if (err) throw err
webpack(webpackConfig, function (err, stats) {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n\n')

if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}

console.log(chalk.cyan(' Build complete.\n'))
console.log(chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
))
})
})
49 changes: 49 additions & 0 deletions webpack4/build/check-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'
const chalk = require('chalk')
const semver = require('semver')
const packageConfig = require('../package.json')
const shell = require('shelljs')
function exec (cmd) {
return require('child_process').execSync(cmd).toString().trim()
}

const versionRequirements = [
{
name: 'node',
currentVersion: semver.clean(process.version),
versionRequirement: packageConfig.engines.node
}
]

if (shell.which('npm')) {
versionRequirements.push({
name: 'npm',
currentVersion: exec('npm --version'),
versionRequirement: packageConfig.engines.npm
})
}

module.exports = function () {
const warnings = []
for (let i = 0; i < versionRequirements.length; i++) {
const mod = versionRequirements[i]
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
warnings.push(mod.name + ': ' +
chalk.red(mod.currentVersion) + ' should be ' +
chalk.green(mod.versionRequirement)
)
}
}

if (warnings.length) {
console.log('')
console.log(chalk.yellow('To use this template, you must update following to modules:'))
console.log()
for (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
console.log(' ' + warning)
}
console.log()
process.exit(1)
}
}
10 changes: 10 additions & 0 deletions webpack4/build/dev-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
'use strict'
require('eventsource-polyfill')
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')

hotClient.subscribe(function (event) {
if (event.action === 'reload') {
window.location.reload()
}
})
Loading

0 comments on commit 29b8fa5

Please sign in to comment.