From 7f420b0caa88a57b13f3094a2d7e599e9bf0c41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 7 May 2021 22:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=BB=9A=E5=8A=A8=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.dev.js | 10 +++++----- build.prod.js | 25 +++++++++++++++---------- src/scroll/index.wc | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/build.dev.js b/build.dev.js index 9211c73..02cd33d 100644 --- a/build.dev.js +++ b/build.dev.js @@ -37,10 +37,10 @@ function fixImport(str) { } function compileJs(entry, output) { - log('编译JS: %s', chalk.green(entry)) - let buf = fs.cat(entry).toString() - let code = fixImport(buf) + var buf = fs.cat(entry).toString() + var code = fixImport(buf) + log('编译JS: %s', chalk.green(entry)) fs.echo(code, output) } @@ -58,7 +58,7 @@ function mkWCFile({ style, html, js }) { 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 .split(/\n+/) .slice(1, -1) @@ -77,7 +77,7 @@ function mkWCFile({ style, html, js }) { }) js = fixImport(js) - .replace(/export default class ([a-zA-Z0-9]+)/, function(s, m) { + .replace(/export default class ([a-zA-Z0-9]+)/, function (s, m) { name = m return `${s} extends HTMLElement ` }) diff --git a/build.prod.js b/build.prod.js index 220860c..1a9e9af 100644 --- a/build.prod.js +++ b/build.prod.js @@ -36,10 +36,12 @@ function fixImport(str) { ) } -const compileJs = (entry, output) => { - let t1 = Date.now() - let buf = fs.cat(entry).toString() +function compileJs(entry, output) { + var t1 = Date.now() + var buf = fs.cat(entry).toString() + buf = fixImport(buf) + minify(buf, { sourceMap: false }).then(res => { log( '编译JS: %s, 耗时 %s ms', @@ -65,19 +67,17 @@ function compileScss(code = '') { } function mkWCFile({ style, html, js }) { + let name = '' style = compileScss(style) - html = html.replace(/[\n\r]+/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 .split(/\n+/) .slice(1, -1) .map(it => { - var tmp = it.split(':') + let tmp = it.split(':') return tmp[0].trim().replace(/^['"]|['"]$/g, '') }) return ` @@ -91,7 +91,7 @@ function mkWCFile({ style, html, js }) { }) js = fixImport(js) - .replace(/export default class ([a-zA-Z0-9]+)/, function(s, m) { + .replace(/export default class ([a-zA-Z0-9]+)/, function (s, m) { name = m return `${s} extends HTMLElement ` }) @@ -137,7 +137,7 @@ if(!customElements.get('wc-${parseName(name)}')){ } const compileWC = (entry, output) => { - log('编译wc: %s', chalk.green(entry)) + let t1 = Date.now() let code = fs.cat(entry).toString() let style = code.match(/]*?>([\w\W]*?)<\/style>/) let html = code.match(/