From cab72f4b83e1b916dd2fa79653a5eb8521c5a0f8 Mon Sep 17 00:00:00 2001 From: nopast <490964186@qq.com> Date: Fri, 8 Mar 2019 17:02:05 +0800 Subject: [PATCH] format --- index.js | 60 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index 145510c..f93e435 100644 --- a/index.js +++ b/index.js @@ -9,44 +9,44 @@ const getRelativePath = (filePath) => { return filePath } -const emitHandle = (compilation, callback) => { - function chunksHandle(chunks) { - const entryChunk = chunks.pop() - - entryChunk.files.forEach(filePath => { - const assetFile = compilation.assets[filePath] - const extname = path.extname(filePath) - let content = assetFile.source() - - 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') { - relativePath = getRelativePath(relativePath) - } - - if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) { - relativePath = getRelativePath(relativePath) - content = `@import "${relativePath}";\n${content}` - } else if (!(/^\.map$/.test(extname))) { - content = `require("${relativePath}")\n${content}` - } +const chunksHandle = (chunks, compilation) => { + const entryChunk = chunks.pop() + + entryChunk.files.forEach(filePath => { + const assetFile = compilation.assets[filePath] + const extname = path.extname(filePath) + let content = assetFile.source() + + 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') { + relativePath = getRelativePath(relativePath) + } + + if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) { + relativePath = getRelativePath(relativePath) + content = `@import "${relativePath}";\n${content}` + } else if (!(/^\.map$/.test(extname))) { + content = `require("${relativePath}")\n${content}` } - }) - assetFile.source = () => content + } }) + assetFile.source = () => content }) - } + }) +} +const emitHandle = (compilation, callback) => { if(compilation.entrypoints instanceof Map) { - compilation.entrypoints.forEach(({chunks}) => chunksHandle(chunks)) + compilation.entrypoints.forEach(({chunks}) => chunksHandle(chunks, compilation)) }else { Object.keys(compilation.entrypoints).forEach(key => { const { chunks } = compilation.entrypoints[key] - chunksHandle(chunks) + chunksHandle(chunks, compilation) }) }