Skip to content

Commit

Permalink
feat(uni-h5-ui): init
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Sep 12, 2019
1 parent c66cfd4 commit da44c7f
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 8 deletions.
18 changes: 13 additions & 5 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), {
// 删除 cache 目录
del.sync(['node_modules/.cache'])

let entry = './lib/' + process.env.UNI_PLATFORM + '/main.js'

if (process.env.UNI_PLATFORM === 'h5' && process.env.UNI_UI === 'true') {
entry = './lib/' + process.env.UNI_PLATFORM + '/ui.js'
}

service.run('build', {
name: 'index',
watch: process.env.UNI_WATCH === 'true',
target: 'lib',
formats: process.env.UNI_WATCH === 'true' ? 'umd' : 'umd-min',
entry: './lib/' + process.env.UNI_PLATFORM + '/main.js'
entry
}).then(function () {
generateApiManifest(
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_MANIFEST)),
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_PROTOCOL))
)
if (process.env.UNI_UI !== 'true') {
generateApiManifest(
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_MANIFEST)),
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_PROTOCOL))
)
}
}).catch(err => {
error(err)
process.exit(1)
Expand Down
8 changes: 7 additions & 1 deletion build/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ const pkgPath = resolve('package.json')

const webpackConfig = require('./webpack.config.js')

let outputDir = resolve('./packages/uni-' + process.env.UNI_PLATFORM + '/dist')

if (process.env.UNI_PLATFORM === 'h5' && process.env.UNI_UI === 'true') {
outputDir = resolve('./packages/uni-' + process.env.UNI_PLATFORM + '-ui/dist')
}

module.exports = {
publicPath: '/',
outputDir: resolve('./packages/uni-' + process.env.UNI_PLATFORM + '/dist'),
outputDir,
lintOnSave: true, // or error
runtimeCompiler: false,
transpileDependencies: [],
Expand Down
27 changes: 27 additions & 0 deletions lib/h5/ui-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
canIUse
} from 'uni-core/service/api/base/can-i-use'
import {
upx2px
} from 'uni-core/service/api/base/upx2px'
import {
getLocation
} from 'uni-platform/service/api/location/get-location'
import {
onCompassChange,
stopCompass
} from 'uni-platform/service/api/device/compass'
import {
getSystemInfoSync
} from 'uni-platform/service/api/device/get-system-info'

// TODO route

export default {
canIUse,
upx2px,
getLocation,
onCompassChange,
stopCompass,
getSystemInfoSync
}
7 changes: 7 additions & 0 deletions lib/h5/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import Vue from 'vue'
// 使用白名单过滤(前期有一批自定义组件使用了 uni-)
import tags from 'uni-helpers/tags'

import 'uni-core/view/index.css'

import uni from './ui-api.js'

const oldIsReservedTag = Vue.config.isReservedTag

global.uni = uni

Vue.config.isReservedTag = function (tag) {
return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
}
Expand All @@ -21,4 +27,5 @@ Vue.config.getTagNamespace = function (tag) {
}
return oldGetTagNamespace(tag) || false
}

require('uni-components')
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"lint:cli": "eslint --fix --config package.json --ignore-path .eslintignore packages/uni-cli-shared packages/uni-template-compiler \"packages/vue-cli-*/**/*.js\" \"packages/webpack-uni-*/**/*.js\"",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:h5:ui": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 UNI_UI=true node build/build.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.mp.js",
"build:app:all": "npm run lint && npm run build:app:nvue && npm run build:app:legacy",
"build:app:nvue": "cross-env UNI_PLATFORM=app-plus-nvue rollup -c build/rollup.config.app.js",
Expand Down
1 change: 1 addition & 0 deletions packages/uni-h5-ui/dist/index.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/uni-h5-ui/dist/index.umd.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/uni-h5-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@dcloudio/uni-h5-ui",
"version": "0.0.1",
"description": "uni-app h5 ui",
"main": "dist/index.umd.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "fxy060608",
"license": "Apache-2.0"
}
5 changes: 4 additions & 1 deletion packages/webpack-uni-pages-loader/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}

function parseStyle (style = {}, root = '') {
function parseStyle (style = {}, root = '') {
// TODO pages.json 触发了两次,需要排查
style = JSON.parse(JSON.stringify(style))

let platformStyle = {}

Object.keys(style).forEach(name => {
Expand Down

0 comments on commit da44c7f

Please sign in to comment.