From 79048a68c89ad4e53db8746b28bff639b3ced95d Mon Sep 17 00:00:00 2001 From: aorz Date: Fri, 20 Jul 2018 21:38:22 +0800 Subject: [PATCH 1/6] publish: 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5db4bf6..83ecad9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-loader", - "version": "1.1.0", + "version": "1.1.1", "description": "mpvue single-file component loader for Webpack", "main": "index.js", "repository": { From 177194f3eec63b9433a5bf0880993a4ffaae56bf Mon Sep 17 00:00:00 2001 From: aorz Date: Mon, 23 Jul 2018 12:28:21 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/template-compiler/modules/transform-require.js | 10 +++++++--- package.json | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/template-compiler/modules/transform-require.js b/lib/template-compiler/modules/transform-require.js index 960d72f..fcf8919 100644 --- a/lib/template-compiler/modules/transform-require.js +++ b/lib/template-compiler/modules/transform-require.js @@ -22,6 +22,10 @@ module.exports = (userOptions, fileOptions) => { } } +function getPathBaseOnSrc (a, b) { + return relative(a, b).replace(/^src\//, '') +} + function transform (node, options, fileOptions) { for (var tag in options) { if (node.tag === tag && node.attrs) { @@ -43,9 +47,9 @@ function rewrite (attrsMap, name, fileOptions) { var { resourcePath, outputPath, context } = fileOptions var assetPath = path.resolve(resourcePath, '..', value) // 资源路径, 为了分包,去掉了 src 目录 - var toPath = relative(context, assetPath).replace(/^\/src\//, '') - attrsMap[name] = path.join(outputPath, toPath) - copyAsset(assetPath, attrsMap[name]) + var toPath = getPathBaseOnSrc(context, assetPath) + attrsMap[name] = relative(getPathBaseOnSrc(context, resourcePath), getPathBaseOnSrc(context, assetPath)) + copyAsset(assetPath, path.join(outputPath, toPath)) } } } diff --git a/package.json b/package.json index 83ecad9..473db5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-loader", - "version": "1.1.1", + "version": "1.1.2-rc.2", "description": "mpvue single-file component loader for Webpack", "main": "index.js", "repository": { From ef093e98b2bd52e34863b0d57f07e316864dc206 Mon Sep 17 00:00:00 2001 From: aorz Date: Tue, 24 Jul 2018 11:17:49 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/util.js | 1 - lib/template-compiler/modules/transform-require.js | 2 +- package.json | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index 4bfeb42..2204732 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -31,7 +31,6 @@ function getCompNameAndSrc (context, file) { function getNameByFile (dir) { // const arr = dir.match(/[pages?/components?]\/(.*?)(\/)/) const arr = dir.match(/pages\/(.*?)\//) - // 兼容 win 下的路径格式不统一的问题 if (arr && arr[1]) { return arr[1] } diff --git a/lib/template-compiler/modules/transform-require.js b/lib/template-compiler/modules/transform-require.js index fcf8919..bd742e8 100644 --- a/lib/template-compiler/modules/transform-require.js +++ b/lib/template-compiler/modules/transform-require.js @@ -48,7 +48,7 @@ function rewrite (attrsMap, name, fileOptions) { var assetPath = path.resolve(resourcePath, '..', value) // 资源路径, 为了分包,去掉了 src 目录 var toPath = getPathBaseOnSrc(context, assetPath) - attrsMap[name] = relative(getPathBaseOnSrc(context, resourcePath), getPathBaseOnSrc(context, assetPath)) + attrsMap[name] = `/${toPath}` copyAsset(assetPath, path.join(outputPath, toPath)) } } diff --git a/package.json b/package.json index 473db5b..f2af2a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-loader", - "version": "1.1.2-rc.2", + "version": "1.1.2-rc.3", "description": "mpvue single-file component loader for Webpack", "main": "index.js", "repository": { From aa2a4108725118a1b8c33c405e4a7a4d2b0c74df Mon Sep 17 00:00:00 2001 From: aorz Date: Tue, 24 Jul 2018 14:02:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E8=BF=87=E6=BB=A4=20node=5Fmodules?= =?UTF-8?q?=20=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/index.js | 22 +++++++++---------- lib/mp-compiler/util.js | 11 ++-------- .../modules/transform-require.js | 9 ++------ lib/utils/resolve-src.js | 7 ++++++ 4 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 lib/utils/resolve-src.js diff --git a/lib/mp-compiler/index.js b/lib/mp-compiler/index.js index 753d8d3..4b8d17e 100644 --- a/lib/mp-compiler/index.js +++ b/lib/mp-compiler/index.js @@ -5,7 +5,6 @@ const babel = require('babel-core') const path = require('path') const fs = require('fs') const deepEqual = require('deep-equal') -const relative = require('../utils/relative') const { parseConfig, parseComponentsDeps, parseGlobalComponents, clearGlobalComponents } = require('./parse') const { parseComponentsDeps: parseComponentsDepsTs } = require('./parse-ts') @@ -51,7 +50,7 @@ function genComponentWxml (compiled, options, emitFile, emitError, emitWarning) function createAppWxml (emitFile, resourcePath, rootComponent, context) { const { src } = getFileInfo(resourcePath) || {} const { name: componentName, filePath: wxmlSrc } = getCompNameAndSrc(context, rootComponent) - const wxmlContent = genPageWxml(componentName, relative(`/${src}.wxml`, `/${wxmlSrc}`)) + const wxmlContent = genPageWxml(componentName, `${wxmlSrc}`) emitFile(`${src}.wxml`, wxmlContent) } // 更新全局组件时,需要重新生成wxml,用这个字段保存所有需要更新的页面及其参数 @@ -118,12 +117,13 @@ function compileWxml (compiled, html) { // 针对 .vue 单文件的脚本逻辑的处理 // 处理出当前单文件组件的子组件依赖 function compileMPScript (script, mpOptioins, moduleId) { + const { resourcePath, options, resolve, context } = this const babelrc = getBabelrc(mpOptioins.globalBabelrc) let result, metadata let scriptContent = script.content const babelOptions = { extends: babelrc, plugins: [parseComponentsDeps] } if (script.src) { // 处理src - const scriptpath = path.join(path.dirname(this.resourcePath), script.src) + const scriptpath = path.join(path.dirname(resourcePath), script.src) scriptContent = fs.readFileSync(scriptpath).toString() } if (script.lang === 'ts') { // 处理ts @@ -138,16 +138,16 @@ function compileMPScript (script, mpOptioins, moduleId) { // 处理子组件的信息 const components = {} - const fileInfo = resolveTarget(this.resourcePath, this.options.entry) + const fileInfo = resolveTarget(resourcePath, options.entry) if (originComponents) { - resolveSrc(originComponents, components, this.resolve, this.context).then(() => { - resolveComponent(this.resourcePath, fileInfo, importsMap, components, moduleId) + resolveSrc(originComponents, components, resolve, context, options.context).then(() => { + resolveComponent(resourcePath, fileInfo, importsMap, components, moduleId) }).catch(err => { console.error(err) - resolveComponent(this.resourcePath, fileInfo, importsMap, components, moduleId) + resolveComponent(resourcePath, fileInfo, importsMap, components, moduleId) }) } else { - resolveComponent(this.resourcePath, fileInfo, importsMap, components, moduleId) + resolveComponent(resourcePath, fileInfo, importsMap, components, moduleId) } return script @@ -183,7 +183,7 @@ function compileMP (content, mpOptioins) { // 解析全局组件的路径 const components = {} - resolveSrc(globalComps, components, resolve, context).then(() => { + resolveSrc(globalComps, components, resolve, context, options.context).then(() => { handleResult(components) }).catch(err => { console.error(err) @@ -220,13 +220,13 @@ function compileMP (content, mpOptioins) { return content } -function resolveSrc (originComponents, components, resolveFn, context) { +function resolveSrc (originComponents, components, resolveFn, context, projectRoot) { return Promise.all(Object.keys(originComponents).map(k => { return new Promise((resolve, reject) => { resolveFn(context, originComponents[k], (err, realSrc) => { if (err) return reject(err) const com = covertCCVar(k) - const { filePath, name } = getCompNameAndSrc(context, realSrc) + const { filePath, name } = getCompNameAndSrc(projectRoot, realSrc) components[com] = { src: filePath, name } resolve() }) diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index 2204732..e9f9132 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -1,7 +1,6 @@ const path = require('path') const fs = require('fs') -const relative = require('../utils/relative') - +const resolveSrc = require('../utils/resolve-src') const pagesNameMap = Object.create(null) function cacheFileInfo (resourcePath, ...arg) { @@ -17,7 +16,7 @@ function getFileInfo (resourcePath) { var hash = require('hash-sum') const cache = Object.create(null) function getCompNameAndSrc (context, file) { - const filePath = `${relative(context, file).replace(/^src\//, '')}.wxml` + const filePath = `/${resolveSrc(context, file)}.wxml` if (!cache[file]) { cache[file] = hash(file) } @@ -122,11 +121,6 @@ function getBabelrc (src) { return '' } -function getPathPrefix (src) { - const length = src.split('/').length - 1 - return `${'../'.repeat(length)}` -} - const defaultStylePart = { type: 'style', content: '\n', @@ -153,6 +147,5 @@ module.exports = { getSlots, htmlBeautify, getBabelrc, - getPathPrefix, getPageSrc } diff --git a/lib/template-compiler/modules/transform-require.js b/lib/template-compiler/modules/transform-require.js index bd742e8..3a3effe 100644 --- a/lib/template-compiler/modules/transform-require.js +++ b/lib/template-compiler/modules/transform-require.js @@ -3,7 +3,7 @@ var fs = require('fs') var path = require('path') var mkdirp = require('mkdirp') -var relative = require('../../utils/relative') +var resolveSrc = require('../../utils/resolve-src') var defaultOptions = { img: 'src', @@ -22,10 +22,6 @@ module.exports = (userOptions, fileOptions) => { } } -function getPathBaseOnSrc (a, b) { - return relative(a, b).replace(/^src\//, '') -} - function transform (node, options, fileOptions) { for (var tag in options) { if (node.tag === tag && node.attrs) { @@ -46,8 +42,7 @@ function rewrite (attrsMap, name, fileOptions) { if (firstChar === '.') { var { resourcePath, outputPath, context } = fileOptions var assetPath = path.resolve(resourcePath, '..', value) - // 资源路径, 为了分包,去掉了 src 目录 - var toPath = getPathBaseOnSrc(context, assetPath) + var toPath = resolveSrc(context, assetPath) attrsMap[name] = `/${toPath}` copyAsset(assetPath, path.join(outputPath, toPath)) } diff --git a/lib/utils/resolve-src.js b/lib/utils/resolve-src.js new file mode 100644 index 0000000..14a8965 --- /dev/null +++ b/lib/utils/resolve-src.js @@ -0,0 +1,7 @@ +const relative = require('relative') +const upath = require('upath') + +// 获取文件路径,去掉 src 和 node_modules 目录 +module.exports = function (...arv) { + return upath.normalize(relative(...arv)).replace(/^src\//, '').replace(/^node_modules\//, 'modules') +} From 0b88b47af4518ad76b5072ea6a84a65cc9c04ba9 Mon Sep 17 00:00:00 2001 From: aorz Date: Tue, 24 Jul 2018 14:30:23 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E5=B5=8C=E5=A5=97=20node=5Fmodules?= =?UTF-8?q?=20=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/index.js | 2 +- lib/utils/resolve-src.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mp-compiler/index.js b/lib/mp-compiler/index.js index 4b8d17e..766a17f 100644 --- a/lib/mp-compiler/index.js +++ b/lib/mp-compiler/index.js @@ -50,7 +50,7 @@ function genComponentWxml (compiled, options, emitFile, emitError, emitWarning) function createAppWxml (emitFile, resourcePath, rootComponent, context) { const { src } = getFileInfo(resourcePath) || {} const { name: componentName, filePath: wxmlSrc } = getCompNameAndSrc(context, rootComponent) - const wxmlContent = genPageWxml(componentName, `${wxmlSrc}`) + const wxmlContent = genPageWxml(componentName, wxmlSrc) emitFile(`${src}.wxml`, wxmlContent) } // 更新全局组件时,需要重新生成wxml,用这个字段保存所有需要更新的页面及其参数 diff --git a/lib/utils/resolve-src.js b/lib/utils/resolve-src.js index 14a8965..712aeae 100644 --- a/lib/utils/resolve-src.js +++ b/lib/utils/resolve-src.js @@ -3,5 +3,5 @@ const upath = require('upath') // 获取文件路径,去掉 src 和 node_modules 目录 module.exports = function (...arv) { - return upath.normalize(relative(...arv)).replace(/^src\//, '').replace(/^node_modules\//, 'modules') + return upath.normalize(relative(...arv)).replace(/^src\//, '').replace(/node_modules\//g, 'modules/') } From 89ba9a03ab5e4b0430e4817ad18714c5f1d29277 Mon Sep 17 00:00:00 2001 From: aorz Date: Mon, 30 Jul 2018 13:46:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20slot=20=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/index.js | 3 +-- lib/mp-compiler/util.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/mp-compiler/index.js b/lib/mp-compiler/index.js index 766a17f..2938960 100644 --- a/lib/mp-compiler/index.js +++ b/lib/mp-compiler/index.js @@ -26,10 +26,9 @@ let slotsHookAdded = false // 调用 compiler 生成 wxml function genComponentWxml (compiled, options, emitFile, emitError, emitWarning) { - options.components['slots'] = { src: 'slots', name: 'slots' } + options.components['slots'] = { src: '/components/slots', name: 'slots' } const { code: wxmlCodeStr, compiled: cp, slots, importCode } = compiler.compileToWxml(compiled, options) const { mpErrors, mpTips } = cp - // 缓存 slots,延迟编译 cacheSlots(slots, importCode) diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index e9f9132..26aa5b1 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -86,7 +86,7 @@ function cacheSlots (slots, importCode) { importCodeCache[importCode] = importCode } function getSlots () { - const allImportCode = Object.keys(importCodeCache).map(v => importCodeCache[v]).join('\n').replace('', '') + const allImportCode = Object.keys(importCodeCache).map(v => importCodeCache[v]).join('\n').replace('', '') const allSlots = Object.keys(slotsCache).map(v => slotsCache[v].code).join('\n') return allImportCode + allSlots } diff --git a/package.json b/package.json index f2af2a5..77f7435 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-loader", - "version": "1.1.2-rc.3", + "version": "1.1.2-rc.5", "description": "mpvue single-file component loader for Webpack", "main": "index.js", "repository": {