Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
BugKun committed Mar 8, 2019
1 parent 0820967 commit cab72f4
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down

0 comments on commit cab72f4

Please sign in to comment.