Skip to content

Commit 3a197fc

Browse files
committed
udpate:头条和支付宝小程序构建支持
1 parent 7a22896 commit 3a197fc

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

index.js

Lines changed: 32 additions & 32 deletions
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 emitHandel = (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', emitHandel)
4040

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

0 commit comments

Comments
 (0)