优化滚动组件
parent
17ce8fe6fa
commit
7f420b0caa
|
@ -37,10 +37,10 @@ function fixImport(str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileJs(entry, output) {
|
function compileJs(entry, output) {
|
||||||
log('编译JS: %s', chalk.green(entry))
|
var buf = fs.cat(entry).toString()
|
||||||
let buf = fs.cat(entry).toString()
|
var code = fixImport(buf)
|
||||||
let code = fixImport(buf)
|
|
||||||
|
|
||||||
|
log('编译JS: %s', chalk.green(entry))
|
||||||
fs.echo(code, output)
|
fs.echo(code, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,12 @@ function fixImport(str) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const compileJs = (entry, output) => {
|
function compileJs(entry, output) {
|
||||||
let t1 = Date.now()
|
var t1 = Date.now()
|
||||||
let buf = fs.cat(entry).toString()
|
var buf = fs.cat(entry).toString()
|
||||||
|
|
||||||
buf = fixImport(buf)
|
buf = fixImport(buf)
|
||||||
|
|
||||||
minify(buf, { sourceMap: false }).then(res => {
|
minify(buf, { sourceMap: false }).then(res => {
|
||||||
log(
|
log(
|
||||||
'编译JS: %s, 耗时 %s ms',
|
'编译JS: %s, 耗时 %s ms',
|
||||||
|
@ -65,19 +67,17 @@ function compileScss(code = '') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkWCFile({ style, html, js }) {
|
function mkWCFile({ style, html, js }) {
|
||||||
|
let name = ''
|
||||||
style = compileScss(style)
|
style = compileScss(style)
|
||||||
|
|
||||||
html = html.replace(/[\n\r]+/g, ' ')
|
html = html.replace(/[\n\r]+/g, ' ')
|
||||||
html = html.replace(/\s+/g, ' ')
|
html = html.replace(/\s+/g, ' ')
|
||||||
|
|
||||||
let name = ''
|
|
||||||
|
|
||||||
js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function (str) {
|
js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function (str) {
|
||||||
var attr = str
|
var attr = str
|
||||||
.split(/\n+/)
|
.split(/\n+/)
|
||||||
.slice(1, -1)
|
.slice(1, -1)
|
||||||
.map(it => {
|
.map(it => {
|
||||||
var tmp = it.split(':')
|
let tmp = it.split(':')
|
||||||
return tmp[0].trim().replace(/^['"]|['"]$/g, '')
|
return tmp[0].trim().replace(/^['"]|['"]$/g, '')
|
||||||
})
|
})
|
||||||
return `
|
return `
|
||||||
|
@ -137,7 +137,7 @@ if(!customElements.get('wc-${parseName(name)}')){
|
||||||
}
|
}
|
||||||
|
|
||||||
const compileWC = (entry, output) => {
|
const compileWC = (entry, output) => {
|
||||||
log('编译wc: %s', chalk.green(entry))
|
let t1 = Date.now()
|
||||||
let code = fs.cat(entry).toString()
|
let code = fs.cat(entry).toString()
|
||||||
let style = code.match(/<style[^>]*?>([\w\W]*?)<\/style>/)
|
let style = code.match(/<style[^>]*?>([\w\W]*?)<\/style>/)
|
||||||
let html = code.match(/<template>([\w\W]*?)<\/template>/)
|
let html = code.match(/<template>([\w\W]*?)<\/template>/)
|
||||||
|
@ -148,6 +148,11 @@ const compileWC = (entry, output) => {
|
||||||
js = js ? js[1] : ''
|
js = js ? js[1] : ''
|
||||||
|
|
||||||
mkWCFile({ style, html, js }).then(txt => {
|
mkWCFile({ style, html, js }).then(txt => {
|
||||||
|
log(
|
||||||
|
'编译WC: %s, 耗时 %s ms',
|
||||||
|
chalk.green(entry),
|
||||||
|
chalk.yellow(Date.now() - t1)
|
||||||
|
)
|
||||||
fs.echo(txt, output)
|
fs.echo(txt, output)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ export default class Scroll {
|
||||||
|
|
||||||
fixedY = fixedY >> 0
|
fixedY = fixedY >> 0
|
||||||
|
|
||||||
if ((fixedY === 0 || height - yBar === fixedY) && fixedY === thumbY) {
|
if (fixedY === thumbY) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ export default class Scroll {
|
||||||
|
|
||||||
fixedX = fixedX >> 0
|
fixedX = fixedX >> 0
|
||||||
|
|
||||||
if ((fixedX === 0 || width - xBar === fixedX) && fixedX === thumbX) {
|
if (fixedX === thumbX) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue