This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0

Compare commits

..

No commits in common. "master" and "2.2.4" have entirely different histories.

3 changed files with 29 additions and 21 deletions

View File

@ -4,11 +4,13 @@
* @date 2018-08-04 01:00:06 * @date 2018-08-04 01:00:06
*/ */
'use strict'
require('es.shim') require('es.shim')
const fs = require('iofs') const fs = require('iofs')
const path = require('path') const path = require('path')
const chokidar = require('chokidar') const chokidar = require('chokidar')
const { minify } = require('terser') const uglify = require('uglify-es')
const chalk = require('chalk') const chalk = require('chalk')
const config = require('./package.json') const config = require('./package.json')
const log = console.log const log = console.log
@ -135,11 +137,8 @@ function packAndCompress() {
*/ */
log('正在打包 anot.js...') log('正在打包 anot.js...')
let normalVerPack = Buffer.concat([PAD_START, normalVer, PAD_END]).toString() let normalVerPack = Buffer.concat([PAD_START, normalVer, PAD_END]).toString()
fs.echo(comment() + uglify.minify(normalVerPack).code, './dist/anot.js')
minify(normalVerPack, { sourceMap: false }).then(res => { log(chalk.green('anot.js 打包压缩完成!'))
fs.echo(comment() + res.code, './dist/anot.js')
log(chalk.green('anot.js 打包压缩完成!'))
})
/** /**
* -------------------------------------------------------- * --------------------------------------------------------
@ -149,10 +148,11 @@ function packAndCompress() {
log('正在打包 anot.touch.js...') log('正在打包 anot.touch.js...')
let touchVerPack = Buffer.concat([PAD_START, touchVer, PAD_END]).toString() let touchVerPack = Buffer.concat([PAD_START, touchVer, PAD_END]).toString()
minify(touchVerPack, { sourceMap: false }).then(res => { fs.echo(
fs.echo(comment({ touch: true }) + res.code, './dist/anot.touch.js') comment({ touch: true }) + uglify.minify(touchVerPack).code,
log(chalk.green('anot.touch.js 打包压缩完成!')) './dist/anot.touch.js'
}) )
log(chalk.green('anot.touch.js 打包压缩完成!'))
} }
let args = process.argv.slice(2) let args = process.argv.slice(2)

View File

@ -14,9 +14,9 @@
"devDependencies": { "devDependencies": {
"chalk": "^2.4.1", "chalk": "^2.4.1",
"chokidar": "^2.0.4", "chokidar": "^2.0.4",
"es.shim": "^2.0.1", "es.shim": "^1.1.2",
"iofs": "^1.5.2", "iofs": "^1.1.0",
"terser": "^5.0.0" "uglify-es": "^3.3.9"
}, },
"repository": "https://github.com/yutent/anot.js.git", "repository": "https://github.com/yutent/anot.js.git",
"author": "yutent", "author": "yutent",

View File

@ -85,7 +85,10 @@ Anot.PropsTypes.isBoolean = function() {
/*判定是否是一个朴素的javascript对象Object不是DOM对象不是BOM对象不是自定义类的实例*/ /*判定是否是一个朴素的javascript对象Object不是DOM对象不是BOM对象不是自定义类的实例*/
Anot.isPlainObject = function(obj) { Anot.isPlainObject = function(obj) {
// 简单的 typeof obj === "object"检测会致使用isPlainObject(window)在opera下通不过 // 简单的 typeof obj === "object"检测会致使用isPlainObject(window)在opera下通不过
return serialize.call(obj) === '[object Object]' && Object.getPrototypeOf(obj) === oproto return (
serialize.call(obj) === '[object Object]' &&
Object.getPrototypeOf(obj) === oproto
)
} }
let VMODELS = (Anot.vmodels = {}) //所有vmodel都储存在这里 let VMODELS = (Anot.vmodels = {}) //所有vmodel都储存在这里
@ -165,7 +168,11 @@ Anot.mix = Anot.fn.mix = function() {
if (target === copy) { if (target === copy) {
continue continue
} }
if (deep && copy && (Anot.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) { if (
deep &&
copy &&
(Anot.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))
) {
if (copyIsArray) { if (copyIsArray) {
copyIsArray = false copyIsArray = false
clone = src && Array.isArray(src) ? src : [] clone = src && Array.isArray(src) ? src : []
@ -271,11 +278,11 @@ Anot.mix({
t = t.trim() t = t.trim()
let hook = hooks[t] let hook = hooks[t]
if (typeof hook === 'object') { if (typeof hook === 'object') {
t = hook.type || t t = hook.type || type
phase = hook.phase || phase phase = hook.phase || !!phase
fn = hook.fix ? hook.fix(el, fn) : fn fn = hook.fix ? hook.fix(el, fn) : fn
} }
el.addEventListener(t, fn, !!phase) el.addEventListener(t, fn, phase)
}) })
return fn return fn
}, },
@ -288,10 +295,10 @@ Anot.mix({
t = t.trim() t = t.trim()
let hook = hooks[t] let hook = hooks[t]
if (typeof hook === 'object') { if (typeof hook === 'object') {
t = hook.type || t t = hook.type || type
phase = hook.phase || phase phase = hook.phase || !!phase
} }
el.removeEventListener(t, fn, !!phase) el.removeEventListener(t, fn, phase)
}) })
}, },
/*读写删除元素节点的样式*/ /*读写删除元素节点的样式*/
@ -459,6 +466,7 @@ Anot.mix({
}, },
//获取url的参数 //获取url的参数
search: function(key) { search: function(key) {
key += ''
let uri = location.search let uri = location.search
if (!uri) { if (!uri) {