Skip to content

Commit b44d6c8

Browse files
committed
feat: update order of inserting CSS
1 parent 92ad022 commit b44d6c8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tests/units/form/form-changed.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ describe("Form.changed", () => {
7878

7979
child.change({name: 'Jack'})
8080

81-
console.log(child.values)
82-
console.log(child.changes)
83-
console.log(parent.changes)
84-
console.log(grandParent.changes)
85-
86-
expect(grandParent.changed).toBe(true)
8781
expect(parent.changed).toBe(true)
8882
expect(child.changed).toBe(true)
8983
})

vite.config.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ export default defineConfig({
2020
...typescript({ tsconfig: resolve(srcFolder, "tsconfig.json"), }),
2121
apply: 'build'
2222
},
23-
cssInjectedByJsPlugin(),
23+
cssInjectedByJsPlugin({
24+
injectCodeFunction: function injectCodeCustomRunTimeFunction(cssCode, options) {
25+
try {
26+
if (!document) return;
27+
28+
const elementStyle = document.createElement('style');
29+
// SET ALL ATTRIBUTES
30+
for (const attribute in options.attributes) {
31+
elementStyle.setAttribute(attribute, options.attributes[attribute]);
32+
}
33+
34+
elementStyle.appendChild(document.createTextNode(cssCode));
35+
document.head.prepend(elementStyle);
36+
} catch (e) {
37+
console.error('vite-plugin-css-injected-by-js', e);
38+
}
39+
}
40+
}),
2441
vue(),
2542

2643
],

0 commit comments

Comments
 (0)