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

adrienne / added svg bundling for wallets #9871

Merged
Merged
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
21 changes: 19 additions & 2 deletions packages/appstore/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = function (env) {
{
loader: 'css-loader',
options: {
url: false,
url: (_, resourcePath) => resourcePath.includes('packages/wallets'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set url resolution for CSS to true only when bundling up wallets package, this ensures that the change only affects wallets package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required otherwise the url in the css will not be resolved to the path in the bundle

},
},
{
Expand Down Expand Up @@ -139,7 +139,24 @@ module.exports = function (env) {
},
{
test: /\.svg$/,
exclude: /node_modules|public\//,
issuer: /\/packages\/wallets\/.*(\/)?.*.scss/,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issuer ensures that the issuer (the parent file who is importing the loaded file) is a CSS/SCSS file and emits the SVG into appstore/wallets/public. This should not be passed into svg_loaders as it will transform it into a React component and inline it within the CSS url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-08-29 at 8 32 36 PM

exclude: /node_modules/,
include: /public\//,
type: 'asset/resource',
generator: {
filename: 'appstore/wallets/public/[name].[contenthash][ext]',
},
},
{
test: /\.svg$/,
issuer: /\/packages\/wallets\/.*(\/)?.*.tsx/,
exclude: /node_modules/,
include: /public\//,
use: svg_loaders,
},
{
test: /\.svg$/,
exclude: [/node_modules|public\//],
use: svg_loaders,
},
],
Expand Down
4 changes: 4 additions & 0 deletions packages/wallets/src/AppContent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import WalletList from './components/WalletList';
import WalletsCarousel from './components/WalletCarousel';
import IcBrandDerivGo from './public/ic-brand-derivgo.svg';
import './app-content.scss';

const AppContent: React.FC = () => {
return (
<div>
<div className='icon' />
<IcBrandDerivGo width={25} height={25} />
<WalletList />
<WalletsCarousel />
</div>
Expand Down
6 changes: 6 additions & 0 deletions packages/wallets/src/app-content.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.icon {
width: 100px;
height: 100px;
background-image: url('./public/ic-appstore-deriv-logo.svg');
background-size: cover;
}
1 change: 1 addition & 0 deletions packages/wallets/src/public/ic-appstore-deriv-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/wallets/src/public/ic-brand-derivgo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.