提交 5c27707f 编写于 作者: qq_39644801's avatar qq_39644801

framework

上级 808bd26d
src/core/helpers/html-parser.js
\ No newline at end of file
module.exports = {
ignore: [
"./packages",
],
presets: [
["@vue/app", {
useBuiltIns: "entry"
}]
]
}
const {
error
} = require('@vue/cli-shared-utils')
const Service = require('@vue/cli-service')
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), {
inlineOptions: require('./vue.config.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'
}).catch(err => {
error(err)
process.exit(1)
})
const path = require('path')
const resolve = dir => path.resolve(__dirname, '../', dir)
const pkgPath = resolve('package.json')
const webpackConfig = require('./webpack.config.js')
module.exports = {
baseUrl: '/',
outputDir: resolve('./packages/uni-' + process.env.UNI_PLATFORM + '/dist'),
lintOnSave: true, // or error
runtimeCompiler: false,
transpileDependencies: [],
productionSourceMap: false,
configureWebpack: webpackConfig,
chainWebpack: config => {
config.devtool('source-map')
config.module
.rule('eslint')
.include
.add(resolve('src'))
.add(resolve('lib/' + process.env.UNI_PLATFORM))
.end()
.use('eslint-loader')
.loader(resolve('node_modules/eslint-loader'))
.options({
fix: true,
configFile: pkgPath
})
config.plugins.delete('hmr') // remove hot module reload
},
css: {
extract: true
}
}
const path = require('path')
const webpack = require('webpack')
const resolve = dir => path.resolve(__dirname, '../', dir)
const pkg = require('../package.json')
module.exports = {
mode: 'production',
devtool: false,
externals: {
vue: {
commonjs: 'vue',
commonjs2: 'vue',
root: 'Vue'
},
'vue-router': {
commonjs: 'vue-router',
commonjs2: 'vue-router',
root: 'VueRouter'
}
},
resolve: {
alias: {
'uni-core': resolve('src/core'),
'uni-view': resolve('src/core/view'),
'uni-service': resolve('src/core/service'),
'uni-shared': resolve('src/shared'),
'uni-mixins': resolve('src/core/view/mixins'),
'uni-helpers': resolve('src/core/helpers'),
'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM)
}
},
module: {
rules: []
},
plugins: [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pkg.version),
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
}),
new webpack.ProvidePlugin({
'console': [resolve('src/core/helpers/console'), 'default'],
'UniViewJSBridge': [resolve('src/core/view/bridge')],
'UniServiceJSBridge': [resolve('src/core/service/bridge')]
})
]
}
const path = require('path')
const webpack = require('webpack')
const resolve = dir => path.resolve(__dirname, '../', dir)
const pkg = require('../package.json')
let service = process.VUE_CLI_SERVICE
if (!service || process.env.VUE_CLI_API_MODE) {
const Service = require('@vue/cli-service')
service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())
service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV)
}
const config = service.resolveWebpackConfig()
config.resolve.alias = {
'@': resolve('src'),
'uni-core': resolve('src/core'),
'uni-view': resolve('src/core/view'),
'uni-service': resolve('src/core/service'),
'uni-shared': resolve('src/shared'),
'uni-mixins': resolve('src/core/view/mixins'),
'uni-helpers': resolve('src/core/helpers'),
'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
'uni-components': resolve('src/core/view/components')
}
const isEslintLoader = config.module.rules[config.module.rules.length - 1].enforce
if (isEslintLoader) {
config.module.rules.splice(config.module.rules.length - 1, 1)
} else {
throw new Error('eslint-loader is undefined')
}
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pkg.version),
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
}),
new webpack.ProvidePlugin({
'UniViewJSBridge': [resolve('src/core/view/bridge')],
'UniServiceJSBridge': [resolve('src/core/service/bridge')]
})
])
module.exports = config
/**
* 1.导出全局对象(UniViewJSBridge,UniServiceJSBridge,uni,getApp,getCurrentPages)
* 2.引入 Vue 插件(uniVueServicePlugin,uniVueServicePlugin)
* 3.引入 Vue 组件
*/
import Vue from 'vue'
global.UniViewJSBridge = {
subscribeHandler: UniViewJSBridge.subscribeHandler
}
global.UniServiceJSBridge = {
subscribeHandler: UniServiceJSBridge.subscribeHandler
}
const {
default: uni,
getApp,
getCurrentPages
} = require('uni-service')
global.uni = Object.assign(uni, require('uni-view').default)
global.wx = global.uni
global.getApp = getApp
global.getCurrentPages = getCurrentPages
Vue.use(require('uni-service/plugins').default, {
routes: __uniRoutes
})
Vue.use(require('uni-view/plugins').default, {
routes: __uniRoutes
})
require('uni-view/components')
{
"name": "uniapp-js-framework",
"version": "0.0.1",
"scripts": {
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"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",
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js"
},
"dependencies": {},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.1.1",
"@vue/cli-plugin-eslint": "^3.1.4",
"@vue/cli-plugin-unit-mocha": "^3.1.1",
"@vue/cli-service": "^3.1.2",
"@vue/test-utils": "^1.0.0-beta.25",
"babel-eslint": "^10.0.1",
"babylon": "^6.18.0",
"chai": "^4.1.2",
"cross-env": "^5.2.0",
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.7.1",
"jsdom": "^13.0.0",
"jsdom-global": "^3.0.2",
"strip-json-comments": "^2.0.1",
"vue": "^2.5.17",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.5.17",
"webpack": "^4.18.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-virtual-modules": "^0.1.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/recommended",
"standard"
],
"globals": {
"getApp": true,
"getCurrentPages": true,
"plus": true,
"uni": true,
"Vue": true,
"wx": true,
"__uniConfig": true,
"__uniRoutes": true,
"UniViewJSBridge": true,
"UniServiceJSBridge": true,
"__PLATFORM__": true,
"__VERSION__": true
},
"rules": {
"no-tabs": 0,
"standard/no-callback-literal": 0
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"license": "ISC",
"main": "index.js",
"description": "",
"author": ""
}
The MIT License (MIT)
Copyright (c) 2017-present, Yuxi (Evan) You
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
{
"name": "@dcloudio/uni-h5",
"version": "0.0.5",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "fxy060608",
"license": "MIT"
}
module.exports = {
plugins: [
require('autoprefixer')({ browsers: ['iOS >= 8', 'Android >= 4'] })
]
}
<svg width="21" height="37" viewBox="0 0 21 37" xmlns="http://www.w3.org/2000/svg"><title>Rectangle 1</title><path d="M17 36L0 19a2.91 2.91 0 0 1 0-1L17 1c.131-.057.5-.06 1 0l2 2c.057.522.06.899 0 1L6 18a.898.898 0 0 0 0 1l14 14c.056.098.062.474 0 1l-2 2c-.494.057-.868.06-1 0z" fill="#FFF" fill-rule="evenodd"/></svg>
\ No newline at end of file
import {
isFn,
isPlainObject
} from 'uni-shared'
import {
tryCatch,
tryCatchFramework
} from './catch'
import protocol from './protocol'
import validateParam from './params'
function invokeCallbackHandlerFail (err, apiName, callbackId) {
const errMsg = `${apiName}:fail ${err}`
console.error(errMsg)
if (callbackId === -1) {
throw new Error(errMsg)
}
if (typeof callbackId === 'number') {
invokeCallbackHandler(callbackId, {
errMsg
})
}
return false
}
const callbackApiParamTypes = [{
name: 'callback',
type: Function,
required: true
}]
function validateParams (apiName, paramsData, callbackId) {
let paramTypes = protocol[apiName]
if (!paramTypes && isCallbackApi(apiName)) {
paramTypes = callbackApiParamTypes
}
if (paramTypes) {
if (Array.isArray(paramTypes) && Array.isArray(paramsData)) {
const paramTypeObj = Object.create(null)
const paramsDataObj = Object.create(null)
const paramsDataLength = paramsData.length
paramTypes.forEach((paramType, index) => {
paramTypeObj[paramType.name] = paramType
if (paramsDataLength > index) {
paramsDataObj[paramType.name] = paramsData[index]
}
})
paramTypes = paramTypeObj
paramsData = paramsDataObj
}
if (isFn(paramTypes.beforeValidate)) {
const err = paramTypes.beforeValidate(paramsData)
if (err) {
return invokeCallbackHandlerFail(err, apiName, callbackId)
}
}
const keys = Object.keys(paramTypes)
for (let i = 0; i < keys.length; i++) {
if (keys[i] === 'beforeValidate') {
continue
}
const err = validateParam(keys[i], paramTypes, paramsData)
if (err) {
return invokeCallbackHandlerFail(err, apiName, callbackId)
}
}
}
return true
}
let invokeCallbackId = 1
const invokeCallbacks = {}
function createKeepAliveApiCallback (apiName, callback) {
const callbackId = invokeCallbackId++
const invokeCallbackName = 'api.' + apiName + '.' + callbackId
const invokeCallback = function (res) {
callback(res)
}
invokeCallbacks[callbackId] = {
name: invokeCallbackName,
keepAlive: true,
callback: invokeCallback
}
return callbackId
}
function createApiCallback (apiName, params = {}, extras = {}) {
if (!isPlainObject(params)) {
return {
params
}
}
params = Object.assign({}, params)
const apiCallbacks = {}
for (let name in params) {
const param = params[name]
if (isFn(param)) {
apiCallbacks[name] = tryCatch(param)
delete params[name]
}
}
const {
success,
fail,
cancel,
complete
} = apiCallbacks
const hasSuccess = isFn(success)
const hasFail = isFn(fail)
const hasCancel = isFn(cancel)
const hasComplete = isFn(complete)
if (!hasSuccess && !hasFail && !hasCancel && !hasComplete) { // 无回调
return {
params
}
}
const wrapperCallbacks = {}
for (let name in extras) {
const extra = extras[name]
if (isFn(extra)) {
wrapperCallbacks[name] = tryCatchFramework(extra)
delete extras[name]
}
}
const {
beforeSuccess,
afterSuccess,
beforeFail,
afterFail,
beforeCancel,
afterCancel,
afterAll
} = wrapperCallbacks
const callbackId = invokeCallbackId++
const invokeCallbackName = 'api.' + apiName + '.' + callbackId
const invokeCallback = function (res) {
res.errMsg = res.errMsg || apiName + ':ok'
const errMsg = res.errMsg
if (errMsg.indexOf(apiName + ':ok') === 0) {
isFn(beforeSuccess) && beforeSuccess(res)
hasSuccess && success(res)
isFn(afterSuccess) && afterSuccess(res)
} else if (errMsg.indexOf(apiName + ':cancel') === 0) {
res.errMsg = res.errMsg.replace(apiName + ':cancel', apiName + ':fail cancel')
hasFail && fail(res)
isFn(beforeCancel) && beforeCancel(res)
hasCancel && cancel(res)
isFn(afterCancel) && afterCancel(res)
} else if (errMsg.indexOf(apiName + ':fail') === 0) {
isFn(beforeFail) && beforeFail(res)
hasFail && fail(res)
isFn(afterFail) && afterFail(res)
}
hasComplete && complete(res)
isFn(afterAll) && afterAll(res)
}
invokeCallbacks[callbackId] = {
name: invokeCallbackName,
callback: invokeCallback
}
return {
params,
callbackId
}
}
function createInvokeCallback (apiName, params = {}, extras = {}) {
const {
params: args,
callbackId
} = createApiCallback(apiName, params, extras)
if (isPlainObject(args) && !validateParams(apiName, args, callbackId)) {
return {
params: args,
callbackId: false
}
}
return {