-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from mpvue/feature/ttalipay
Feature/ttalipay
- Loading branch information
Showing
2 changed files
with
33 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 emitHandle = (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', emitHandle) | ||
|
||
module.exports = MpvuePlugin; | ||
module.exports = MpvuePlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters