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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vite-plugin-qingkuai",
3
3
  "author": "mlgq",
4
4
  "license": "MIT",
5
- "version": "1.0.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
@@ -6,7 +6,10 @@ export default rollup.defineConfig(() => {
6
6
  external: [
7
7
  "vite",
8
8
  "postcss",
9
+ "node:fs",
9
10
  "node:path",
11
+ "node:crypto",
12
+ "source-map-js",
10
13
  "merge-source-map",
11
14
  "qingkuai/compiler",
12
15
  "@ampproject/remapping",
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.style[index]
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, viteConfig)
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.style.forEach((_, index) => {
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
- exposeDestruction: isDev,
211
+ exposeDestructions: isDev,
188
212
  exposeDependencies: isDev,
189
213
  resolveImportExtension: true,
190
214
  reserveHtmlComments: "development"
package/src/scope.ts CHANGED
@@ -37,6 +37,7 @@ export async function attachScopeForStyleSelectors(code: string, hash: string, m
37
37
  ])
38
38
 
39
39
  const ret = await processor.process(code, {
40
+ from: map.file,
40
41
  map: {
41
42
  prev: map,
42
43
  annotation: false
package/src/types.ts CHANGED
@@ -10,7 +10,7 @@ export interface SourceMap {
10
10
  }
11
11
 
12
12
  export type QingkuaiConfiguration = Partial<{
13
- exposeDestruction: boolean
13
+ exposeDestructions: boolean
14
14
  exposeDependencies: boolean
15
15
  insertTipComments: boolean
16
16
  resolveImportExtension: boolean