Skip to content

Commit 71c60ba

Browse files
committed
add: 百度小程序适配
1 parent 0dbedd8 commit 71c60ba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ MpvuePlugin.prototype.apply = function(compiler) {
1616
chunks.reverse().forEach(chunk => {
1717
chunk.files.forEach(childFile => {
1818
if (path.extname(childFile) === extname && compilation.assets[filePath]) {
19-
const relativePath = upath.normalize(relative(filePath, childFile))
20-
content = extname === '.wxss' ?
21-
`@import "${relativePath}";\n${content}`
22-
: `require("${relativePath}");\n${content}`;
19+
let relativePath = upath.normalize(relative(filePath, childFile))
20+
21+
// 百度小程序js引用不支持绝对路径,改为相对路径
22+
if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) {
23+
relativePath = `./${relativePath}`;
24+
}
25+
26+
if (/^(\.wxss)|(\.css)$/.test(extname)) {
27+
content = `@import "${relativePath}";\n${content}`;
28+
} else {
29+
content = `require("${relativePath}");\n${content}`;
30+
}
2331
}
2432
})
2533
compilation.assets[filePath].source = () => content;

0 commit comments

Comments
 (0)