Skip to content

Commit

Permalink
feat: import uri?raw as text
Browse files Browse the repository at this point in the history
  • Loading branch information
yingyiyang authored and sxzz committed Jun 26, 2023
1 parent 46faae7 commit 5adce61
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/output/moduleCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ function processModule(store: Store, src: string, filename: string) {
// import * as ok from 'foo' --> ok -> __import_foo__
if (node.type === 'ImportDeclaration') {
const source = node.source.value
// import 'foo/style.css' --> <link rel="stylesheet" href="" />, href is import.meta.resolve('foo/style.css')
// import 'http://127.0.0.1/style.css' --> <link rel="stylesheet" href="http://127.0.0.1/style.css" />
if (source.endsWith('.css')) {
if (source.endsWith('?raw')) {
const url = source.slice(0, -4)
s.overwrite(node.start!, node.end!, `const ${node.specifiers[0].local.name} = await (await fetch(${url.startsWith('http') ? `'${url}'` : `import.meta.resolve('${url}')`})).text()`)
} else if (source.endsWith('.css')) {
// import 'foo/style.css' --> <link rel="stylesheet" href="" />, href is import.meta.resolve('foo/style.css')
// import 'http://127.0.0.1/style.css' --> <link rel="stylesheet" href="http://127.0.0.1/style.css" />
s.overwrite(node.start!, node.end!, `if(true){
const link = document.createElement('link');
link.rel = 'stylesheet';
Expand Down

0 comments on commit 5adce61

Please sign in to comment.