vite-plugin-qingkuai 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/rollup.config.js +3 -0
- package/src/index.ts +29 -5
- package/src/scope.ts +1 -0
- package/src/types.ts +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "vite-plugin-qingkuai",
|
|
3
3
|
"author": "mlgq",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"vite",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "rollup -c -w",
|
|
21
|
-
"build": "rimraf dist && rollup -c"
|
|
21
|
+
"build": "rimraf dist && rollup -c",
|
|
22
|
+
"postpublish": "curl -X PUT 'https://registry-direct.npmmirror.com/-/package/vite-plugin-qingkuai/sync'"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/fs-extra": "^11.0.4",
|
package/rollup.config.js
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,7 +21,10 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
21
21
|
const parseFailedConfigFiles: string[] = []
|
|
22
22
|
const compileResultCache = new Map<string, CompileResult>()
|
|
23
23
|
const qingkuaiConfigurations = new Map<string, QingkuaiConfiguration>()
|
|
24
|
+
|
|
25
|
+
const confIdentifierRE = /__qk_expose_(?:dependencies|destructions)__/g
|
|
24
26
|
const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/
|
|
27
|
+
const qingkuaiPackageRE = /node_modules\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/
|
|
25
28
|
|
|
26
29
|
return {
|
|
27
30
|
name: "qingkuai-compiler",
|
|
@@ -65,7 +68,7 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
65
68
|
|
|
66
69
|
let virtualFileName: string
|
|
67
70
|
const compileRes = compileResultCache.get(fileId)!
|
|
68
|
-
const style = compileRes.inputDescriptor.
|
|
71
|
+
const style = compileRes.inputDescriptor.styles[index]
|
|
69
72
|
|
|
70
73
|
// create a relative and not existing file name
|
|
71
74
|
while (true) {
|
|
@@ -76,7 +79,15 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
const preprocessRes = await preprocessCSS(style.code, virtualFileName,
|
|
82
|
+
const preprocessRes = await preprocessCSS(style.code, virtualFileName, {
|
|
83
|
+
...viteConfig,
|
|
84
|
+
css: {
|
|
85
|
+
...viteConfig.css,
|
|
86
|
+
postcss: {
|
|
87
|
+
from: virtualFileName
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
80
91
|
if (!cssSourcemap) {
|
|
81
92
|
return preprocessRes.code
|
|
82
93
|
}
|
|
@@ -109,11 +120,24 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
109
120
|
},
|
|
110
121
|
|
|
111
122
|
async transform(src, id) {
|
|
123
|
+
const qingkuaiConfig = getQingkuaiConfiguration(id)
|
|
112
124
|
if (!id.endsWith(".qk")) {
|
|
125
|
+
if (!isDev && qingkuaiPackageRE.test(id)) {
|
|
126
|
+
const ret = src.replace(confIdentifierRE, s => {
|
|
127
|
+
switch (s) {
|
|
128
|
+
case "__qk_expose_dependencies__":
|
|
129
|
+
return JSON.stringify(!!qingkuaiConfig.exposeDependencies)
|
|
130
|
+
case "__qk_expose_destructions__":
|
|
131
|
+
return JSON.stringify(!!qingkuaiConfig.exposeDestructions)
|
|
132
|
+
default:
|
|
133
|
+
return s
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
return ret
|
|
137
|
+
}
|
|
113
138
|
return
|
|
114
139
|
}
|
|
115
140
|
|
|
116
|
-
const qingkuaiConfig = getQingkuaiConfiguration(id)
|
|
117
141
|
const compileRes = compile(src, {
|
|
118
142
|
sourcemap,
|
|
119
143
|
debug: isDev,
|
|
@@ -129,7 +153,7 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
129
153
|
compileResultCache.set(id, compileRes)
|
|
130
154
|
|
|
131
155
|
const compiledCodeArr = [compileRes.code]
|
|
132
|
-
compileRes.inputDescriptor.
|
|
156
|
+
compileRes.inputDescriptor.styles.forEach((_, index) => {
|
|
133
157
|
compiledCodeArr.push(`import "virtual:[${index}]${id}.css?${Date.now()}"`)
|
|
134
158
|
})
|
|
135
159
|
|
|
@@ -184,7 +208,7 @@ export default function qingkuaiPlugin(): Plugin {
|
|
|
184
208
|
function getQingkuaiConfiguration(id: string) {
|
|
185
209
|
let config: QingkuaiConfiguration = {
|
|
186
210
|
insertTipComments: true,
|
|
187
|
-
|
|
211
|
+
exposeDestructions: isDev,
|
|
188
212
|
exposeDependencies: isDev,
|
|
189
213
|
resolveImportExtension: true,
|
|
190
214
|
reserveHtmlComments: "development"
|
package/src/scope.ts
CHANGED
package/src/types.ts
CHANGED