Skip to content

Commit 1955b4b

Browse files
committed
bugfix: add";" after import in css
1 parent cfad04a commit 1955b4b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const path = require('path')
22
const upath = require('upath')
33
const relative = require('relative')
44

5+
const getRelativePath = (filePath) => {
6+
if (!/^\.(\.)?\//.test(filePath)) {
7+
filePath = `./${filePath}`
8+
}
9+
return filePath
10+
}
11+
512
const emitHandle = (compilation, callback) => {
613
Object.keys(compilation.entrypoints).forEach(key => {
714
const { chunks } = compilation.entrypoints[key]
@@ -16,13 +23,15 @@ const emitHandle = (compilation, callback) => {
1623
chunk.files.forEach(subFile => {
1724
if (path.extname(subFile) === extname && assetFile) {
1825
let relativePath = upath.normalize(relative(filePath, subFile))
26+
1927
// 百度小程序 js 引用不支持绝对路径,改为相对路径
20-
if (extname === '.js' && !/^\.(\.)?\//.test(relativePath)) {
21-
relativePath = `./${relativePath}`
28+
if (extname === '.js') {
29+
relativePath = getRelativePath(relativePath)
2230
}
2331

2432
if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) {
25-
content = `@import "${relativePath}"\n${content}`
33+
relativePath = getRelativePath(relativePath)
34+
content = `@import "${relativePath}";\n${content}`
2635
} else {
2736
content = `require("${relativePath}")\n${content}`
2837
}

package.json

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

0 commit comments

Comments
 (0)