{"id":15674814,"url":"https://github.com/ptrdom/scalajs-vite","last_synced_at":"2025-04-28T15:43:11.610Z","repository":{"id":94132995,"uuid":"576968599","full_name":"ptrdom/scalajs-vite","owner":"ptrdom","description":"Bundles Scala.js projects and their npm dependencies with Vite","archived":false,"fork":false,"pushed_at":"2025-04-20T15:07:41.000Z","size":410,"stargazers_count":16,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-20T15:34:07.089Z","etag":null,"topics":["npm","scala-js","vite"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ptrdom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-11T15:15:26.000Z","updated_at":"2025-04-20T15:07:20.000Z","dependencies_parsed_at":"2024-01-21T17:28:37.573Z","dependency_job_id":"d36612de-e3c6-4117-9e7b-4a7a813c6aa9","html_url":"https://github.com/ptrdom/scalajs-vite","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptrdom%2Fscalajs-vite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptrdom%2Fscalajs-vite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptrdom%2Fscalajs-vite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptrdom%2Fscalajs-vite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptrdom","download_url":"https://codeload.github.com/ptrdom/scalajs-vite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251340936,"owners_count":21574015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm","scala-js","vite"],"created_at":"2024-10-03T15:51:11.091Z","updated_at":"2025-04-28T15:43:11.582Z","avatar_url":"https://github.com/ptrdom.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scalajs-vite\n\nscalajs-vite is a module bundler for Scala.js projects that use npm packages: it bundles the .js files emitted by the \nScala.js compiler with their npm dependencies into a single .js file using Vite.\n\n[![sbt-scalajs-vite Scala version support](https://index.scala-lang.org/ptrdom/scalajs-vite/sbt-scalajs-vite/latest.svg)](https://index.scala-lang.org/ptrdom/scalajs-vite/sbt-scalajs-vite)\n\n## Getting started\n\nPlugin should feel quite familiar to the users of well known [scalajs-bundler](https://scalacenter.github.io/scalajs-bundler), \nwith the main difference being that there is no special handling of `npmDependencies` - they must be provided through \n`package.json` placed within `vite` directory in project's base.\n\n### Basic setup\n\n1. Setup project layout, following is a minimal example:\n\n   ```\n   src\n     main\n      scala\n        example\n          Main.scala # Scala.js entrypoint\n   vite\n     index.html # Vite entrypoint\n     package.json # devDependencies must provide Vite package\n   ```\n\n1. Add plugin to sbt project:\n\n   ```scala\n   addSbtPlugin(\"me.ptrdom\" % \"sbt-scalajs-vite\" % scalaJSViteVersion)\n   ```\n\n1. Enable plugin in `build.sbt`:\n\n   ```\n   enablePlugins(ScalaJSVitePlugin)\n   ```\n   \n1. Specify that Scala.js project is an application with an entrypoint:\n\n   ```\n   scalaJSUseMainModuleInitializer := true\n   ```\n   \n   Such configuration would allow `main.js` bundle to be used in Vite entrypoint:\n\n   ```html\n   \u003cscript type=\"module\" src=\"/main.js\"\u003e\u003c/script\u003e\n   ```\n\n1. Use sbt tasks to compile Scala.js code and run Vite:\n   - For development-like `vite dev`:\n     - `fastLinkJS/startVite;~fastLinkJS/viteCompile;fastLinkJS/stopVite`\n   - For production-like `vite preview`:\n     - `fullLinkJS/startPreview;~fullLinkJS/viteBuild;fullLinkJS/stopPreview`\n\nRunning `fullLinkJS/viteBuild` produces a production-ready `vite build` in `/target/${scalaVersion}/vite/main/dist` \ndirectory.\n\nAll files in `vite` directory are copied to Vite working directory, so any other web resources and relevant configuration\nfiles can be put there.\n\nSee [sbt-scalajs-vite/src/sbt-test/sbt-scalajs-vite/basic-project](sbt-scalajs-vite/src/sbt-test/sbt-scalajs-vite/basic-project) directory for basic example project.\n\n### Integrating with sbt-web\n\n1. Add plugin to sbt project:\n\n   ```scala\n   addSbtPlugin(\"me.ptrdom\" % \"sbt-web-scalajs-vite\" % scalaJSViteVersion)\n   ```\n\n1. Enable plugin in `build.sbt`:\n\n   ```scala\n   lazy val server = project\n     .settings(\n       scalaJSProjects := Seq(client),\n       pipelineStages := Seq(scalaJSPipeline)\n     )\n     .enablePlugins(WebScalaJSVitePlugin)\n    \n   lazy val client = project.enablePlugins(ScalaJSVitePlugin)\n   ```\n\nSee [sbt-web-scalajs-vite/src/sbt-test/sbt-web-scalajs-vite/basic-project](sbt-web-scalajs-vite/src/sbt-test/sbt-web-scalajs-vite/basic-project) directory for basic example project.\n\n## Package managers\n\n\nUses [npm](https://www.npmjs.com/) by default, but provided `PackageManager` abstraction allows configuration of other\npackage managers.\n\n```scala\n//for yarn\nvitePackageManager := new scalajsvite.PackageManager {\n  override def name = \"yarn\"\n  override def lockFile = \"yarn.lock\"\n  override def installCommand = \"install\"\n}\n\n// for pnpm\nvitePackageManager := new scalajsvite.PackageManager {\n  override def name = \"pnpm\"\n  override def lockFile = \"pnpm-lock.yaml\"\n  override def installCommand = \"install\"\n}\n```\n\n## Electron\n\nPlugin is also suitable for working with [Electron](https://www.electronjs.org/) projects. Each Electron script should \nbe specified as a separate module in `scalaJSModuleInitializers`:\n\n```scala \nscalaJSModuleInitializers := Seq(\n  ModuleInitializer\n    .mainMethodWithArgs(\"example.Main\", \"main\")\n    .withModuleID(\"main\"),\n  ModuleInitializer\n    .mainMethodWithArgs(\"example.Preload\", \"main\")\n    .withModuleID(\"preload\"),\n  ModuleInitializer\n    .mainMethodWithArgs(\"example.Renderer\", \"main\")\n    .withModuleID(\"renderer\")\n)\n```\n\nThen the typical Electron workflows can be executed\nwith the use of [vite-plugin-electron](https://github.com/electron-vite/vite-plugin-electron).\n\nSee [sbt-scalajs-vite/src/sbt-test/sbt-scalajs-vite/electron-project](sbt-scalajs-vite/src/sbt-test/sbt-scalajs-vite/electron-project) directory for example project.\n\n## License\n\nThis software is licensed under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptrdom%2Fscalajs-vite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptrdom%2Fscalajs-vite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptrdom%2Fscalajs-vite/lists"}