The best way to get started with CodeOnly will depend on what you're trying to achieve...
Learn the basics by running simple experiments right here in your browser.
The easiest way to add CodeOnly to a project - no server required.
For use with popular build and bundling tools like Vite, Rollup, Webpack etc...
Generate a single page app for use with simple file server or full server.
A full-stack single page app. Client SPA, server, live reload and Docker ready.
If you just want to experiment with and learn about CodeOnly, the CodeOnly Lab is the perfect way to get started. You can write simple components and experiment with them right in your browser.
The Lab expects a component class called "Main" as the entry point to your experiment.
Save your experiments by clicking the Copy Link button - that'll copy a link to your clipboard that you can use to share your experiments and to reload them later.
Clicking the "Copy Link" button also places the link in the browser address bar so you can refresh to get back to a previous save point or use browser bookmarks to save your experiments.
The ".html" button will download a .html file containing your experiment. You'll still need a web connection to run it because it gets JavaScript and CSS files via CDN, but it's an easy way to make a simple web app.
The Lab only supports a single source code file but you can still use multiple components - just put them one after the other.
CDN packages for CodeOnly are available via jsDelivr.
ES6 Library:
https://cdn.jsdelivr.net/gh/codeonlyjs/core@0.0.78/dist/codeonly.js
Minimized ES6 Library:
https://cdn.jsdelivr.net/gh/codeonlyjs/core@0.0.78/dist/codeonly.min.js
See the jsdelivr docs for more information on selecting specific versions.
The easiest way to use these packages is with an import map:
<script type="importmap">
{
"imports": {
"@codeonlyjs/core": "https://cdn.jsdelivr.net/gh/codeonlyjs/core@0.0.78/dist/codeonly.min.js"
}
}
</script>
You can then import from the library using the same @codeonlyjs/core
package name as the NPM packages:
<script type="module">
import { Component, css } from "@codeonlyjs/core";
// etc...
</script>
The CodeOnly NPM package is available from github:
npm install --save codeonlyjs/core
The NPM package can be used with bundling tools like Rollup and Browserify or build servers like Vite and Snowpack.
Consider using a CodeOnly Full Stack Project as an alternative to a development build server.
A CodeOnly SPA Project is an easy way to get started on a single page app.
It includes the entry index.html file, a router, home page, header bar, and Stylish theme with light/dark mode support.
An SPA Project requires a file server and won't work by just opening the index.html from the file system. The project includes instructions on how to easily work around this.
To create a CodeOnly Single Page App project:
You'll need NodeJS to run the CLI tool - get it here.
From a command prompt, enter the following command (replacing "MyNewProject" with the name of your project):
npx codeonlyjs/cogent new spa MyNewProject
This will create a new directory containing everything required for a client side single page app.
Included in the new project directory will be a readme.md file with information about the project structure and instructions on how to run it during development and build it for production.
A CodeOnly Full-Stack project is an alternative to using a development build server (eg: Vite, SnowPack etc...).
Rather than running a both a front-end build server and a back-end web server, a CodeOnly full-stack project includes a NodeJS/ExpressJS server that does both.
This has some nice advantages, especially during development:
For production:
Most of this is made possible with our related product Bundle-free.
Even if you don't plan to use the full-stack project's web server during production, a full-stack project still provides an great development environment and you can still bundle and deploy to a separate production server later if necessary.
A full-stack project includes a front-end single page app client with entry index.html file, a router, home page, header bar, and Stylish theme with light/dark mode support.
To generate a full stack project:
You'll need NodeJS to run the CLI tool - get it here.
From a command prompt, enter the following command (replacing "MyNewProject" with the name of your project):
npx codeonlyjs/cogent new fullstack MyNewProject
This will create a new directory containing the new project files.
Included in the new project directory will be a readme.md file with information about the project structure and instructions on how to run it during development and build it for production.