Skip to content

Commit 035903a

Browse files
author
yingyiyang
committed
feat: import uri?raw as text
1 parent 769bc93 commit 035903a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/output/moduleCompiler.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ function processModule(
132132
// import * as ok from 'foo' --> ok -> __import_foo__
133133
if (node.type === 'ImportDeclaration') {
134134
const source = node.source.value
135-
// import 'foo/style.css' --> <link rel="stylesheet" href="" />, href is import.meta.resolve('foo/style.css')
136-
// import 'http://127.0.0.1/style.css' --> <link rel="stylesheet" href="http://127.0.0.1/style.css" />
137-
if (source.endsWith('.css')) {
135+
if (source.endsWith('?raw')) {
136+
const url = source.slice(0, -4)
137+
s.overwrite(node.start!, node.end!, `const ${node.specifiers[0].local.name} = await (await fetch(${url.startsWith('http') ? `'${url}'` : `import.meta.resolve('${url}')`})).text()`)
138+
} else if (source.endsWith('.css')) {
139+
// import 'foo/style.css' --> <link rel="stylesheet" href="" />, href is import.meta.resolve('foo/style.css')
140+
// import 'http://127.0.0.1/style.css' --> <link rel="stylesheet" href="http://127.0.0.1/style.css" />
138141
s.overwrite(node.start!, node.end!, `if(true){
139142
const link = document.createElement('link');
140143
link.rel = 'stylesheet';

0 commit comments

Comments
 (0)