Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use SVGR to load SVGs as components #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14,745 changes: 9,574 additions & 5,171 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@stylable/cli": "^5.8.0",
"@stylable/runtime": "^5.8.0",
"@stylable/webpack-plugin": "^5.8.0",
"@svgr/webpack": "^6.5.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.56.0",
Expand Down
7 changes: 0 additions & 7 deletions src/_codux/boards/header/header.board.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/assets/codux.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/assets/stylable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/header.st.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

.anchor {}

.icon {}
.logo {}
10 changes: 8 additions & 2 deletions src/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type React from 'react';
import { st, classes } from './header.st.css';
import stylableLogo from './assets/stylable.svg';
import StylableLogo from './assets/stylable.svg';

export interface HeaderProps {
className?: string;
Expand All @@ -19,7 +19,13 @@ export const Header: React.FC<HeaderProps> = ({ className }) => {
>
Stylable!
</a>{' '}
<img className={classes.icon} src={stylableLogo} width={50} height={50} alt="" />
<img
src={StylableLogo}
className={classes.logo}
width="60"
height="60"
title="Stylable Logo"
/>
</h1>
</header>
);
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
Expand Down
20 changes: 15 additions & 5 deletions typings/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ declare module '*.st.css' {
export default defaultExport;
}

declare module '*.svg' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<
React.ComponentProps<'svg'> & { title?: string }
>;

export default ReactComponent;
}

declare module '*.svg?url' {
const assetUrl: string;
export default assetUrl;
}

declare module '*.png' {
const urlToFile: string;
export default urlToFile;
Expand All @@ -24,8 +39,3 @@ declare module '*.gif' {
const urlToFile: string;
export default urlToFile;
}

declare module '*.svg' {
const urlToFile: string;
export default urlToFile;
}
18 changes: 17 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ export default {
},
},
{
test: /\.(png|jpg|jpeg|gif|svg|eot|ttf|woff|woff2)$/,
test: /\.svg$/i,
type: 'asset',
resourceQuery: /url/, // *.svg?url
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url
use: [
{
loader: '@svgr/webpack',
options: {},
},
],
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2)$/,
type: 'asset',
},
],
Expand Down