For contributors
Architecture
Section titled “Architecture”Project structure
Section titled “Project structure”This project is a monorepo with the following structure:
apps- applications.docs- documentation website.
demos- demos.all- meta-package for all demos.inline- inline demos for various pages outside of specific framework context.*- demos for each supported framework.
packages- loader itself, integrations and internal utilities.integration-utils- utility functions and constants for integrations. Bundled with the loader to allow users to write their own integrations.loader- loader’s source code.types- types for usage throughout the project.utils- various utilities for usage throughout the project.*-integration- specific framework integration.vite-astro-entry-generator- a plugin that generates an Astro component that loads a script on the client side.vite-awesome-svg-loader- final loader bundle (in other words, meta-package).vite-file-tree-builder- a plugin that builds a project’s file tree.
modules.d.ts- types for untyped external modules.
Monorepo management
Section titled “Monorepo management”Turborepo is used to manage monorepo.
Demos are self-contained NPM packages.
All demos should contain their own scripts and assets. The code and the assets are often duplicated across the demos.
When demo is built, its file tree is formed that will be displayed in the docs website.
Demos should be small and should not have a sprawling file tree.
Demos are built in Vite library mode and rebuilt whenever a change occurs. This pattern avoids necessity for the running multiple web servers.
Scripts
Section titled “Scripts”generate-sources- generates project’s source code required for building. Runs automatically before any other build command.build- builds whole project.build:packages- builds all packages. Use this while developing to speed up the build.build:apps- builds all apps.build:demos- builds all demos.dev- builds all packages and executesdevall dev commands. This command is resource heavy!dev:docs:standalone- runsdevcommand fordocspackages without running all demos in watch mode. This is a lighter alternative todev. The docs are still updated whenever demo is rebuilt.lint- lints the code with ESLint.format- formats the code with Prettier.
TypeScript and JavaScript
Section titled “TypeScript and JavaScript”The primary language for this project is TypeScript. TypeScript should be used while developing loader itself, integrations and demos.
However, build scripts are written in JS to simplify development and speed up the build. Typing is not critical for these scripts. Thus, TypeScript is just not worth it.
Bundlers
Section titled “Bundlers”Vite is the primary bundler for this project.
Other bundlers may be used, if Vite ecosystem doesn’t have a solution, or specific package requires specific tooling. Examples:
vite-awesome-svg-loadermeta-package usestsdownbecause no other tool was able to correctly build types for multiple entry points.docsapp uses Astro and its tooling (it’s Vite internally, but it may change in future).
Custom build scripts and/or plugins may be used in the build process. Ideally, custom additions to the build process should be implemented as bundler’s plugins or build lifecycle hooks. But plain JS scripts are OK, if it makes life easier.
Bundle structure
Section titled “Bundle structure”Every project (package, demo or app) should be bundled into dist directory inside the project’s root.
For example, packages/utils bundle should be in packages/utils/dist directory.
Dependencies
Section titled “Dependencies”Dependencies that are used by more than one project should be installed for the whole project, i.e. added to the root package.json.
Such dependencies include Vite, TypeScript, Vue, React, Solid, etc.
Local dependencies should be installed in package or app where they’re required.
vite-awesome-svg-loader final bundle dependencies always should be in packages/vite-awesome-svg-loader/package.json file even if they’re duplicated in the root package.json.
Build process
Section titled “Build process”This is how build command works:
generate-sourcescommand is ran, and the source code is generated:vite-awesome-svg-loadersource code is generated:- Loader and integrations re-exports are added.
- Subpath exports are updated.
- Loader and all integrations are added as dependencies.
all-demospackage is generated: all demos are added as dependencies.
- All packages are built.
vite-awesome-svg-loaderpackage is built.- All demos are built.
- Apps are built.
Code style
Section titled “Code style”Prettier should be used to format the code. Styles that are left for the user to decide are handled by ESLint rules.
This project tries to keep the source code clean and readable. Please, try to do so as well, i.e. don’t stack ifs too many times, don’t use bit shifts unnecessarily, etc.
Integrations development
Section titled “Integrations development”- Create an issue to notify the community that you’ll be working on your integration.
- Create an integration package using
npx turbo generate workspacecommand or by copying an existing integration. - Develop integration:
- Open
package.jsonfile inside your integration directory. - Add
"integration-utils": "*"dependency. - Develop your integration.
- Open
- Run
npm run generate-sourcescommand to regeneratevite-awesome-svg-loadersource code. Or just run any build or dev command. - Develop demos for your integration:
- Duplicate any existing demo and pages in the
/apps/docs/src/content/docsdirectory. - Develop your demos.
- Update the docs:
- Add a glob import for the demos inside
/apps/docs/src/demosdirectory. - Update the previously copied pages.
- Feel free to add your own pages if needed.
- Add a glob import for the demos inside
- Duplicate any existing demo and pages in the
- Submit a PR with your integration.
Loader development
Section titled “Loader development”- Create an issue to notify the community that you’ll be working on your feature.
- Develop your feature. Make sure to document it with JSDoc.
- Update the docs to showcase your feature.
- Test if demos work.
- Submit a PR.