-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(guide): add javascript section with overview and quickstart pages #4226
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
Open
joesphchang
wants to merge
7
commits into
ionic-team:main
Choose a base branch
from
joesphchang:add-ionic-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+770
−0
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
747bdbe
docs(javascript): added overview and ionic-core page
joesphchang 97cb601
docs(javascript): ran npm run lint
joesphchang 16342aa
Merge branch 'main' into pr/4226
brandyscarney 0d0e2ee
feat(javascript): update overview to match others and add JS logo
brandyscarney 2139b34
refactor(javascript): move ionic-core to quickstart
brandyscarney 3ed1139
refactor(javascript): update quickstart to match other framework flows
brandyscarney e5495eb
docs(javascript): update quickstart links and logos
brandyscarney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
title: 'Ionic Core Custom Components' | ||
sidebar_label: Ionic Core | ||
--- | ||
|
||
# Setting Up an Ionic Core Project with Vite (Vanilla JS) | ||
|
||
This guide walks you through integrating [Ionic Core](https://ionicframework.com/docs/components) with a plain JavaScript (Vanilla) project using Vite. You'll get tree-shaking support, efficient bundle sizes, and a solid development experience. | ||
|
||
# 1. Navigate to your desired directory and create a new Vite project | ||
|
||
Open your terminal and run: | ||
|
||
```shell | ||
npm create vite@latest my-vanilla-ionic-app -- --template vanilla | ||
``` | ||
|
||
# 2. Move into your project folder | ||
|
||
```shell | ||
cd my-vanilla-ionic-app | ||
``` | ||
|
||
# 3. Install project dependencies | ||
|
||
Install both Vite's dependencies and Ionic Core: | ||
|
||
```shell | ||
npm install | ||
npm install @ionic/core | ||
``` | ||
|
||
# 5. Link Ionic CSS in `index.html` | ||
|
||
Add the following `<link>` inside the `<head>` tag in index.html: | ||
|
||
`<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" />` | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<title>Ionic Core - Example</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" /> | ||
</head> | ||
<body> | ||
<ion-app> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>My Ionic App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button expand="block">Click Me</ion-button> | ||
</ion-content> | ||
</ion-app> | ||
</body> | ||
</html> | ||
``` | ||
|
||
# 6. Configure main.js for Tree-Shaking | ||
|
||
- Open your project's main JavaScript entry file, which Vite typically names `main.js` in the project's root. | ||
- Add the Ionic `defineCustomElements` code to this file: | ||
|
||
```js | ||
import { defineCustomElements } from '@ionic/core/loader'; | ||
|
||
const resourcesUrl = '/'; | ||
|
||
defineCustomElements(window, { | ||
components: ['ion-app', 'ion-button', 'ion-card', 'ion-header', 'ion-toolbar', 'ion-title', 'ion-content'], | ||
resourcesUrl: resourcesUrl, | ||
}); | ||
``` | ||
|
||
# 7. Run the Development Server | ||
|
||
Now that we're finally all set-up we can start our development server: | ||
|
||
```shell | ||
npm run dev | ||
``` | ||
|
||
Your app will be available at http://localhost:5173. You should see Ionic-styled components working as expected. | ||
|
||
9. Build for Production: | ||
|
||
```shell | ||
npm run build | ||
``` | ||
|
||
The optimized production build will be output to the dist/ directory. Tree-shaking ensures only the components listed in main.js are included. | ||
|
||
# Bonus: Framework Integrations | ||
|
||
You can use Ionic Web Components in other frameworks that support custom elements. | ||
|
||
Live examples below: | ||
|
||
- [Svelte](https://stackblitz.com/edit/vitejs-vite-bp6vxnem?file=src%2FApp.svelte) | ||
|
||
- [Alpine.JS](https://stackblitz.com/edit/vitejs-vite-kg36bvri?file=index.html) | ||
|
||
- [Lit.JS](https://stackblitz.com/edit/vitejs-vite-twfn9ilc?file=package.json) | ||
|
||
> Note: When integrating Ionic Core into projects using libraries such as Svelte, Alpine, or Lit, be aware that you won't have the built-in form and routing capabilities that are tightly coupled with Ionic's official Angular, React, and Vue framework integrations. You'll need to handle these aspects using the patterns and tools provided by your chosen library. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: 'Ionic JavaScript Overview' | ||
sidebar_label: Overview | ||
--- | ||
|
||
<head> | ||
<title>Ionic JavaScript Overview | JavaScript Version Support and Tooling</title> | ||
<meta | ||
name="description" | ||
content="@ionic/javascript combines the Ionic experience with the tooling and APIs tailored to React developers. Learn more about version support and resources in our React Overview." | ||
/> | ||
</head> | ||
|
||
import DocsCard from '@components/global/DocsCard'; | ||
import DocsCards from '@components/global/DocsCards'; | ||
|
||
`@ionic/javascript` offers a powerful way to build cross-platform applications using JavaScript, and it integrates seamlessly with modern tooling like Vite. This combination allows you to leverage your existing JavaScript knowledge and the efficiency of Vite to create high-quality, performant apps with Ionic's extensive UI library and native capabilities. | ||
|
||
## JavaScript Version Support | ||
|
||
Ionic JavaScript, when used with Vite, supports the latest versions of JavaScript, ensuring you can use modern language features in your projects. | ||
|
||
## JavaScript Tooling | ||
|
||
Ionic JavaScript is designed to work hand-in-hand with the JavaScript CLI and popular tooling. When you choose Vite as your build tool, you gain access to its incredibly fast development server and optimized build process. You can continue to use your favorite JavaScript libraries for state management, testing, and more within this ecosystem. | ||
|
||
## Native Tooling | ||
|
||
[Capacitor](https://capacitorjs.com) is the official cross-platform runtime for Ionic JavaScript, enabling your apps to run natively on iOS, Android, and the web with a single codebase. | ||
|
||
## Installation | ||
|
||
```shell-session | ||
$ npm create vite@latest myApp -- --template vanilla | ||
$ npm install && npm install @ionic/core | ||
$ npm run dev | ||
``` | ||
|
||
## Resources | ||
|
||
<DocsCards> | ||
|
||
<DocsCard header="Ionic Core" href="ionic-core" icon="/icons/guide-quickstart-icon.png"> | ||
<p>Quickly set-up your JavaScript application with Ionic Custom Components.</p> | ||
</DocsCard> | ||
|
||
</DocsCards> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.