From 3a197fc757a04e6774e0c642a076026bfe91c79c Mon Sep 17 00:00:00 2001 From: hucq Date: Tue, 15 Jan 2019 22:24:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?udpate:=E5=A4=B4=E6=9D=A1=E5=92=8C=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=AE=9D=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 64 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 858f55b..5e28a48 100644 --- a/index.js +++ b/index.js @@ -1,41 +1,41 @@ -const path = require('path'); -const upath = require('upath'); -const relative = require('relative'); +const path = require('path') +const upath = require('upath') +const relative = require('relative') -function MpvuePlugin() {} +const emitHandel = (compilation, callback) => { + Object.keys(compilation.entrypoints).forEach(key => { + const { chunks } = compilation.entrypoints[key] + const entryChunk = chunks.pop() -MpvuePlugin.prototype.apply = function(compiler) { - compiler.plugin('emit', function(compilation, callback) { - Object.keys(compilation.entrypoints).forEach(key => { - const entry = compilation.entrypoints[key]; - const { chunks } = entry; - const entryChunk = chunks.pop(); - entryChunk.files.forEach(filePath => { - const extname = path.extname(filePath); - let content = compilation.assets[filePath].source(); - chunks.reverse().forEach(chunk => { - chunk.files.forEach(childFile => { - if (path.extname(childFile) === extname && compilation.assets[filePath]) { - let relativePath = upath.normalize(relative(filePath, childFile)) + entryChunk.files.forEach(filePath => { + const assetFile = compilation.assets[filePath] + const extname = path.extname(filePath) + let content = assetFile.source() - // 百度小程序js引用不支持绝对路径,改为相对路径 - if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) { - relativePath = `./${relativePath}`; - } + chunks.reverse().forEach(chunk => { + chunk.files.forEach(subFile => { + if (path.extname(subFile) === extname && assetFile) { + let relativePath = upath.normalize(relative(filePath, subFile)) + // 百度小程序 js 引用不支持绝对路径,改为相对路径 + if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) { + relativePath = `./${relativePath}` + } - if (/^(\.wxss)|(\.css)$/.test(extname)) { - content = `@import "${relativePath}";\n${content}`; - } else { - content = `require("${relativePath}");\n${content}`; - } + if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) { + content = `@import "${relativePath}"\n${content}` + } else { + content = `require("${relativePath}")\n${content}` } - }) - compilation.assets[filePath].source = () => content; + } }) + assetFile.source = () => content }) }) - callback(); - }); -}; + }) + callback() +} + +function MpvuePlugin() {} +MpvuePlugin.prototype.apply = compiler => compiler.plugin('emit', emitHandel) -module.exports = MpvuePlugin; +module.exports = MpvuePlugin From 3e9f15b236bd515f12e166f65de12fc3f1508fb5 Mon Sep 17 00:00:00 2001 From: hucq Date: Tue, 15 Jan 2019 22:25:55 +0800 Subject: [PATCH 2/3] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38ec498..2936fa1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack-mpvue-asset-plugin", - "version": "0.1.2", + "version": "0.1.3", "main": "index.js", "directories": { "lib": "lib" From cfad04ab751167f72553098eb30f28aa757d8f89 Mon Sep 17 00:00:00 2001 From: hucq Date: Tue, 15 Jan 2019 22:32:39 +0800 Subject: [PATCH 3/3] spell check --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5e28a48..358f774 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const path = require('path') const upath = require('upath') const relative = require('relative') -const emitHandel = (compilation, callback) => { +const emitHandle = (compilation, callback) => { Object.keys(compilation.entrypoints).forEach(key => { const { chunks } = compilation.entrypoints[key] const entryChunk = chunks.pop() @@ -36,6 +36,6 @@ const emitHandel = (compilation, callback) => { } function MpvuePlugin() {} -MpvuePlugin.prototype.apply = compiler => compiler.plugin('emit', emitHandel) +MpvuePlugin.prototype.apply = compiler => compiler.plugin('emit', emitHandle) module.exports = MpvuePlugin