-
-
Notifications
You must be signed in to change notification settings - Fork 266
Usage with SvelteKit #598
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
Comments
I would also like to report that importing components like this: import { Button } from 'carbon-components-svelte'; is much slower than like this: import Button from 'carbon-components-svelte/src/Button/Button.svelte'; in SvelteKit during first load of |
@jjonescz This was a huge issue for me as well, and the reason for the The preprocessor will resolve the base import to the source Svelte file. Before:
- import { Button } from "carbon-components-svelte";
- import { Notification20 } from "carbon-icons-svelte";
After:
+ import Button from "carbon-components-svelte/Button/Button.svelte";
+ import Notification20 from "carbon-icons-svelte/lib/Notification20/Notification20.svelte"; This is better than the sub-folder import approach (i.e., Usage Like with any Svelte preprocessor, add it to the list of preprocessors in your Svelte config: // svelte.config.js
const { optimizeCarbonImports } = require("carbon-components-svelte/preprocess");
module.exports = {
preprocess: [optimizeCarbonImports()],
}; EDIT: If you're reading this, SvelteKit now uses ESM for the // svelte.config.js
import { optimizeImports } from "carbon-preprocess-svelte";
export default {
preprocess: [optimizeImports()],
}; |
I came here because I wanted to raise an issue, but it seems related to this: I'm using Svelte with Vite and Routify (so not SvelteKit) and importing the Tile Component caused a SyntaxError Another thing that might be related somehow: Trying to load the theme using |
Any update on this? I really want to try Carbon with Sveltekit and i can wait for more documents and stable version. |
Got ParseError: Unexpected token
at error (/home/me/Projects/xx/node_modules/svelte/compiler.js:16752:20)
at Parser$1.error (/home/me/Projects/xx/node_modules/svelte/compiler.js:16828:10)
at Parser$1.acorn_error (/home/me/Projects/xx/node_modules/svelte/compiler.js:16822:15)
at Object.read_script [as read] (/home/me/Projects/xx/node_modules/svelte/compiler.js:7501:17)
at tag (/home/me/Projects/xx/node_modules/svelte/compiler.js:15887:34)
at new Parser$1 (/home/me/Projects/xx/node_modules/svelte/compiler.js:16787:22)
at parse$3 (/home/me/Projects/xx/node_modules/svelte/compiler.js:16919:21)
at script (/home/me/Projects/xx/node_modules/carbon-components-svelte/preprocess/optimize-carbon-imports.js:46:19)
at process_single_tag (/home/me/Projects/xx/node_modules/svelte/compiler.js:30241:34)
at /home/me/Projects/xx/node_modules/svelte/compiler.js:30113:28 while trying sveltekit and optimizeCarbonImports. I have the optimizeDeps setup. Why nobody in svelte tooling world prints what currently is being parsed and failed parsing/processing so we could even report it better is beyond me. 👀 😄 |
@arekbal Try |
Ho about creating a SvelteKit example in the README? |
I can't get I also tried |
I'm also trying to use Carbon with Sveltekit. I've tried the following, in
|
@magick93 Do you have |
I have also an issue with it seems that vite cant find the icons Failed to resolve import "carbon-icons-svelte/lib/Close20/Close20.svelte" from "node_modules/carbon-components-svelte/src/UIShell/SideNav/HamburgerMenu.svelte". Does the file exist? while the carbon-icons-svelte is installed |
@alpap What versions for SvelteKit and Carbon? |
@metonym |
@alpap So far, I was not able to reproduce with the following:
Using the UI Shell with the menu: <!-- src/routes/index.svelte -->
<script>
import {
Header,
HeaderNav,
HeaderNavItem,
HeaderNavMenu,
SideNav,
SideNavItems,
SideNavMenu,
SideNavMenuItem,
SideNavLink,
SideNavDivider,
SkipToContent,
Content,
Grid,
Row,
Column,
} from "carbon-components-svelte";
let isSideNavOpen = false;
</script>
<svelte:head>
<link
rel="stylesheet"
href="https://unpkg.com/carbon-components-svelte/css/white.css"
/>
</svelte:head>
<Header company="IBM" platformName="Carbon Svelte" bind:isSideNavOpen>
<div slot="skip-to-content">
<SkipToContent />
</div>
<HeaderNav>
<HeaderNavItem href="/" text="Link 1" />
<HeaderNavItem href="/" text="Link 2" />
<HeaderNavItem href="/" text="Link 3" />
<HeaderNavMenu text="Menu">
<HeaderNavItem href="/" text="Link 1" />
<HeaderNavItem href="/" text="Link 2" />
<HeaderNavItem href="/" text="Link 3" />
</HeaderNavMenu>
<HeaderNavItem href="/" text="Link 4" />
</HeaderNav>
</Header>
<SideNav bind:isOpen={isSideNavOpen}>
<SideNavItems>
<SideNavLink text="Link 1" />
<SideNavLink text="Link 2" />
<SideNavLink text="Link 3" />
<SideNavMenu text="Menu">
<SideNavMenuItem href="/" text="Link 1" />
<SideNavMenuItem href="/" text="Link 2" />
<SideNavMenuItem href="/" text="Link 3" />
</SideNavMenu>
<SideNavDivider />
<SideNavLink text="Link 4" />
</SideNavItems>
</SideNav>
<Content>
<Grid>
<Row>
<Column>
<h1>Welcome</h1>
</Column>
</Row>
</Grid>
</Content>
package.json: {
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview"
},
"devDependencies": {
"@sveltejs/kit": "next",
"carbon-components-svelte": "^0.45.1",
"carbon-icons-svelte": "^10.38.0",
"svelte": "^3.42.6"
},
"type": "module"
}
Does the above look correct? What package manager are you using? |
I found the issue the problem was that i was importing a library called |
we are deploying application using react js with ibm carbon but looks like the load of the page is too slow . requesting for a solution |
Hi @edumpus01 You're commenting on a closed issue for the Carbon Svelte repository, but it appears you have a concern with React. I recommend opening a discussion here: https://github.com/carbon-design-system/carbon/discussions And be sure to provide details such as whether you're using Vite, Next.js, and what your Lighthouse metrics are, specifically 'first contentful paint' and 'total blocking time'. |
Uh oh!
There was an error while loading. Please reload this page.
Update July 5, 2021
It is no longer necessary to instruct vite to optimize
clipboard-copy
as of carbon-components-svelte v0.39.The
clipboard-copy
dependency has been removed (PR #726).Instead,
CodeSnippet
andCopyButton
use the native, asynchronous Clipboard API to copy text. The functionality is exported as a prop so the user can override the behavior as needed.Note: the
clipboard.writeText
API is not supported in IE 11 nor Safari iOS version 13.3 or lower. caniuse estimates that ~91% of global users use a browser compatible with the API.Overriding default copy behavior
Override the default functionality through the
copy
prop.Preventing default copy behavior
Pass a "no-op" empty function to prevent the component from copying text at all.
A number of issues have been raised regarding using this library with SvelteKit. This is very important as it seems that SvelteKit will become the de facto framework for building SSR/SPA/static apps with Svelte.
Issues: #594
Refs:
Currently, this library has a dependency that does not support ESM (clipboard-copy).
Therefore, it must be manually added to the list of dependencies for
vite
to optimize:This is not ideal because there shouldn't be an extra step to use the library.
Todo:
clipboard-copy
with an ESM alternativeThe text was updated successfully, but these errors were encountered: