Search
Loading...
Skip to content

New Vanilla Svelte Project

This guide walks you through the process of creating a Svelte project (without using SvelteKit) and integrating CreativeEditor SDK (CE.SDK) with a custom component. By the end of this guide, you’ll have a fully functional CE.SDK component running in your Svelte application, ready for customization.

Who Is This Guide For?#

This guide is for developers who:

  • Have basic experience with Svelte.
  • Are looking to set up a new vanilla Svelte project.
  • Want to build a Svelte application (without SvelteKit) that includes a fully-featured image and video editor component.

What You’ll Achieve#

  • Initialize a new Svelte project using Vite.
  • Install CE.SDK via NPM.
  • Use CE.SDK to create a basic image and video creative editor Svelte component with default settings.
  • Render the custom CE.SDK Svelte component in your application.

Prerequisites#

Before getting started, verify that have the following:

Step 1: Set Up a New Svelte Project#

Using a build tool like Vite, Parcel, or RSBuild is an efficient way to initialize a new Svelte project. In this tutorial, we’ll use Vite.

To create a new vanilla Svelte project named my-svelte-app, run the following Vite command:

Terminal window
npm create vite@latest my-svelte-app -- --template svelte

Or, equivalently, on Windows:

Terminal window
npm create vite@latest my-svelte-app --template svelte

A new Svelte project will be created in the my-svelte-app folder. Move into the project folder by running:

Terminal window
cd my-svelte-app

The Svelte project structure should look like this:

my-svelte-app/
├── .vscode # VS Code settings for your project
│ └── extensions.json # Recommended extensions
├── public # Static assets folder
│ └── vite.svg # Default Vite logo
└── src # Source code of the app
│ ├── assets # Static assets used by the app
│ │ └── svelte.svg # Svelte logo
│ │
│ ├── lib # Reusable components or libraries
│ │ └── Counter.svelte # A sample component
│ │
│ ├── app.css # Global styles
│ ├── App.svelte # Main Svelte component
│ ├── main.js # JavaScript entry point
│ └── vite-env.d.ts # Type definitions for Vite
├── .gitignore # Files to ignore in Git
├── index.html # Main HTML file
├── jsconfig.json # JS config (helps with IntelliSense)
├── package.json # Project metadata, dependencies, scripts
├── README.md # Project documentation
├── svelte.config.js # Svelte project config
└── vite.config.js # Vite build tool config

To install the project dependencies, execute:

Terminal window
npm install

Step 2: Install CE.SDK#

Add CreativeEditor SDK to your project’s dependencies by installing the @cesdk/cesdk-js NPM package:

Terminal window
npm install @cesdk/cesdk-js

Step 3: Create Your Creative Editor Svelte Component#

In the src/lib/ folder of your new Svelte project, create a new file named CreativeEditorSDK.svelte containing the following component:

<script>
import CreativeEditorSDK from "@cesdk/cesdk-js";
import { onDestroy, onMount } from "svelte";
// reference to the container HTML element where CE.SDK will be initialized
let container;
// where to keep track of the CE.SDK instance
let cesdk = null;
// deafult CreativeEditor SDK configuration
const defaultConfig = {
license: "<YOUR_LICENSE_KEY>", // replace it with a valid CE.SDK license key
callbacks: { onUpload: "local" }, // enable local file uploads in the Asset Library
// other default configs...
};
// accessing the component's props
const { el, children, class: _, config, ...props } = $props();
// hook to initialize the CreativeEditorSDK component
onMount(() => {
// integrate the configs read from props with the default ones
const ceSDKConfig = {
...defaultConfig,
...config,
}
try {
// initialize the CreativeEditorSDK instance in the container element
// using the given config
CreativeEditorSDK.create(container, ceSDKConfig).then(async (instance) => {
cesdk = instance;
// do something with the instance of CreativeEditor SDK (e.g., populate
// the asset library with default / demo asset sources)
await Promise.all([
cesdk.addDefaultAssetSources(),
cesdk.addDemoAssetSources({ sceneMode: "Design" }),
]);
// create a new design scene in the editor
await cesdk.createDesignScene();
});
} catch (err) {
console.warn(`CreativeEditor SDK failed to mount.`, { err });
}
});
// hook to clean up when the component unmounts
onDestroy(() => {
try {
// dispose of the CE.SDK instance if it exists
if (cesdk) {
cesdk.dispose();
cesdk = null;
}
} catch (err) {
// log error if CreativeEditor SDK fails to unmount
console.warn(`CreativeEditor SDK failed to unmount.`, { err });
}
});
</script>
<!-- the container HTML element where the CE.SDK editor will be mounted -->
<div id="cesdk_container" bind:this={container}></div>
<style>
/* styling for the CE.SDK container element to take full viewport size */
#cesdk_container {
height: 100vh;
width: 100vw;
}
</style>

This Svelte component initializes a CreativeEditor SDK instance with basic configuration inside a <div> container element defined in the component’s HTML section. When the component unmounts, the CE.SDK instance is properly disposed of to free up resources.

Step 4: Use the Creative Editor Component#

Import the CreativeEditorSDK component in your App.svelte file by adding the following line in the <script> section:

import CreativeEditorSDK from './lib/CreativeEditorSDK.svelte';

To render the component in the template section of your App.svelte, add it like this:

<script>
// other imports...
import CreativeEditorSDK from "./lib/CreativeEditorSDK.svelte";
</script>
<main>
<!-- other components... -->
<CreativeEditorSDK
config={{
// custom configs ...
}}
/>
<!-- other components... -->
</main>
<style>
/* custom stylying... */
</style>

Or, without custom configuration:

<CreativeEditorSDK />

App.svelte will contain something like:

<script>
// other imports...
import CreativeEditorSDK from "./lib/CreativeEditorSDK.svelte";
</script>
<main>
<!-- other components... -->
<CreativeEditorSDK
config={{
// custom configs ...
}}
/>
<!-- other components... -->
</main>
<style>
/* custom stylying... */
</style>

Step 5: Serve the Svelte Project Locally#

To run the project locally, start the development server provided by Vite with the following command:

Terminal window
npm run dev

By default, the Svelte app will be available on your localhost at http://localhost:5173/.

Step 6: Test the Integration#

  1. Open http://localhost:5173/ in your browser.
  2. A fully functional CE.SDK editor should load.

Troubleshooting & Common Errors#

❌ Error: The $props rune is only available inside .svelte and .svelte.js/ts files

  • Make sure to load the CreativeEditorSDK.svelte component’s props using $props() in the top-level <script> section, not inside onMount() or other lifecycle functions.

❌ Error: The following dependencies are imported but could not be resolved: @cesdk/cesdk-js

  • Verify that you’ve correctly installed CE.SDK via npm install @cesdk/cesdk-js.

❌ Error: Editor engine could not be loaded: The License Key (API Key) you are using to access CE.SDK is invalid

  • Double-check that your license key is valid and hasn’t expired.

    ❌ Editor does not load

  • Check the browser console for any errors.

  • Verify that your component paths and imports are correct.

Next Steps#

Congratulations! You’ve successfully integrated CE.SDK into your new Svelte project. Now, take some time to explore the SDK and move on to the next steps whenever you’re ready: