Skip to content

Commit f7b9e8d

Browse files
authored
Merge pull request #8 from mpvue/feature/ttalipay
Feature/ttalipay
2 parents 7a22896 + cfad04a commit f7b9e8d

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

index.js

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
const path = require('path');
2-
const upath = require('upath');
3-
const relative = require('relative');
1+
const path = require('path')
2+
const upath = require('upath')
3+
const relative = require('relative')
44

5-
function MpvuePlugin() {}
5+
const emitHandle = (compilation, callback) => {
6+
Object.keys(compilation.entrypoints).forEach(key => {
7+
const { chunks } = compilation.entrypoints[key]
8+
const entryChunk = chunks.pop()
69

7-
MpvuePlugin.prototype.apply = function(compiler) {
8-
compiler.plugin('emit', function(compilation, callback) {
9-
Object.keys(compilation.entrypoints).forEach(key => {
10-
const entry = compilation.entrypoints[key];
11-
const { chunks } = entry;
12-
const entryChunk = chunks.pop();
13-
entryChunk.files.forEach(filePath => {
14-
const extname = path.extname(filePath);
15-
let content = compilation.assets[filePath].source();
16-
chunks.reverse().forEach(chunk => {
17-
chunk.files.forEach(childFile => {
18-
if (path.extname(childFile) === extname && compilation.assets[filePath]) {
19-
let relativePath = upath.normalize(relative(filePath, childFile))
10+
entryChunk.files.forEach(filePath => {
11+
const assetFile = compilation.assets[filePath]
12+
const extname = path.extname(filePath)
13+
let content = assetFile.source()
2014

21-
// 百度小程序js引用不支持绝对路径,改为相对路径
22-
if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) {
23-
relativePath = `./${relativePath}`;
24-
}
15+
chunks.reverse().forEach(chunk => {
16+
chunk.files.forEach(subFile => {
17+
if (path.extname(subFile) === extname && assetFile) {
18+
let relativePath = upath.normalize(relative(filePath, subFile))
19+
// 百度小程序 js 引用不支持绝对路径,改为相对路径
20+
if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) {
21+
relativePath = `./${relativePath}`
22+
}
2523

26-
if (/^(\.wxss)|(\.css)$/.test(extname)) {
27-
content = `@import "${relativePath}";\n${content}`;
28-
} else {
29-
content = `require("${relativePath}");\n${content}`;
30-
}
24+
if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) {
25+
content = `@import "${relativePath}"\n${content}`
26+
} else {
27+
content = `require("${relativePath}")\n${content}`
3128
}
32-
})
33-
compilation.assets[filePath].source = () => content;
29+
}
3430
})
31+
assetFile.source = () => content
3532
})
3633
})
37-
callback();
38-
});
39-
};
34+
})
35+
callback()
36+
}
37+
38+
function MpvuePlugin() {}
39+
MpvuePlugin.prototype.apply = compiler => compiler.plugin('emit', emitHandle)
4040

41-
module.exports = MpvuePlugin;
41+
module.exports = MpvuePlugin

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-mpvue-asset-plugin",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"main": "index.js",
55
"directories": {
66
"lib": "lib"

0 commit comments

Comments
 (0)