Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 436c074

Browse files
authored
Fix #101, check for existence of document before injecting css (#114)
* fix: check for existence of document before injecting css * test: update generated code in fixture
1 parent 48a8ea2 commit 436c074

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/vueTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export default async function vueTransform (code, id, options) {
238238
const style = css.map(s => '$compiled' in s ? s.$compiled.code : s.code).join('\n').replace(/(\r?\n|[\s])+/g, ' ')
239239
const styleCode = `
240240
(function(){
241-
if(document){
241+
if(typeof document !== 'undefined'){
242242
var head=document.head||document.getElementsByTagName('head')[0],
243243
style=document.createElement('style'),
244244
css=${JSON.stringify(style)};

test/expects/no-css-extract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){ if(document){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=".baz { color: #008000; } .bar { color: blue } .foo { color: red; } "; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
1+
(function(){ if(typeof document !== 'undefined'){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=".baz { color: #008000; } .bar { color: blue } .foo { color: red; } "; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
22

33

44

0 commit comments

Comments
 (0)