Skip to content

Commit

Permalink
remove import './styles.css' from script
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Jan 23, 2024
1 parent c853df6 commit 89111d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/livecodes/compiler/import-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export const removeImports = (code: string, mods: string[]) =>
return mods.includes(libName) ? '' : statement;
});

export const removeSideEffectStyleImports = (code: string) =>
code.replace(/import\s+["']\.\/style(s)?\.(css|less|sass|scss)["'];?/g, '');

export const styleimportsPattern =
/(?:@import\s+?)((?:".*?")|(?:'.*?')|(?:url\('.*?'\))|(?:url\(".*?"\)))(.*)?;/g;

Expand Down
2 changes: 2 additions & 0 deletions src/livecodes/result/result-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
hasImports,
isModuleScript,
removeImports,
removeSideEffectStyleImports,
} from '../compiler';
import { cssPresets, getLanguageCompiler, getLanguageExtension } from '../languages';
import { hasCustomJsxRuntime, hasDefaultExport, reactRuntime } from '../languages/jsx/jsx-runtime';
Expand Down Expand Up @@ -118,6 +119,7 @@ export const createResultPage = async ({
dom.head.appendChild(stylesheet);
});
code.script.compiled = removeImports(code.script.compiled, stylesheetImports);
code.script.compiled = removeSideEffectStyleImports(code.script.compiled);

// editor styles
if (singleFile) {
Expand Down

0 comments on commit 89111d0

Please sign in to comment.