@lls/vitescripts 2.0.15 → 2.0.17

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/vitescripts",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
@@ -34,7 +34,7 @@ export default ({ prefix = '', llsCssModuleMacroPluginArg }) => {
34
34
  loader: 'js'
35
35
  }
36
36
  })
37
- build.onDispose(async () => {
37
+ build.onEnd(async () => {
38
38
  await fs.promises.rm(tmpDir, { recursive: true })
39
39
  })
40
40
  }
package/src/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default as llsAssetsPlugin } from './llsAssetsPlugin.mjs'
2
2
  export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin.mjs'
3
- export { default as llsLinariaSsrCollectPlugin } from './llsLinariaSsrCollectPlugin.mjs'
3
+ export { default as llsCssSsrCollectPlugin } from './llsCssSsrCollectPlugin.mjs'
4
4
  export { default as llsRequirePlugin } from './llsRequirePlugin.mjs'
5
5
  export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin.mjs'
6
6
  export { default as llsVitestMockPlugin } from './llsVitestMockPlugin.mjs'
@@ -0,0 +1,25 @@
1
+ /**
2
+ * flushStyles() method that generates and return <style> tag with refreshed style
3
+ */
4
+ import { transform } from 'lightningcss'
5
+ const llsCssSsrCollectPlugin = () => {
6
+ const cssIds = new Map()
7
+ return {
8
+ name: 'lls:llsCssSsrCollectPlugin',
9
+ transform(src, id) {
10
+ if (/module\.css$/.test(id)) {
11
+ cssIds.set(id, src)
12
+ }
13
+ },
14
+ flushStyles() {
15
+ const css = [...cssIds.values()].join('\n')
16
+
17
+ // when hmr, id changes but not css-selector so we get two rules with the same css-selector
18
+ // we dedupe the rules so old rule is now stripped.
19
+ const { code } = transform({ code: Buffer.from(css) })
20
+ return `<style id="cssmodule-ssr-collect-plugin">${code.toString()}</style>`
21
+ }
22
+ }
23
+ }
24
+
25
+ export default llsCssSsrCollectPlugin