{"id":17132849,"url":"https://github.com/maximekjaer/scalajs-webpack-loader","last_synced_at":"2025-04-13T07:56:26.086Z","repository":{"id":40724718,"uuid":"241360586","full_name":"MaximeKjaer/scalajs-webpack-loader","owner":"MaximeKjaer","description":"Webpack loader for Scala.js","archived":false,"fork":false,"pushed_at":"2022-12-30T20:01:11.000Z","size":1235,"stargazers_count":25,"open_issues_count":17,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T07:56:20.483Z","etag":null,"topics":["scalajs","webpack","webpack-loader"],"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/MaximeKjaer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-18T12:54:03.000Z","updated_at":"2024-01-21T08:56:41.000Z","dependencies_parsed_at":"2023-01-31T15:15:15.711Z","dependency_job_id":null,"html_url":"https://github.com/MaximeKjaer/scalajs-webpack-loader","commit_stats":null,"previous_names":["maximekjaer/scalajs-webpack"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeKjaer%2Fscalajs-webpack-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeKjaer%2Fscalajs-webpack-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeKjaer%2Fscalajs-webpack-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeKjaer%2Fscalajs-webpack-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaximeKjaer","download_url":"https://codeload.github.com/MaximeKjaer/scalajs-webpack-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681489,"owners_count":21144700,"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":["scalajs","webpack","webpack-loader"],"created_at":"2024-10-14T19:28:34.607Z","updated_at":"2025-04-13T07:56:26.065Z","avatar_url":"https://github.com/MaximeKjaer.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# scalajs-webpack-loader\n\n\u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg alt=\"Webpack logo\" src=\"https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg\" height=\"150\"/\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/scala-js/scala-js\"\u003e\n    \u003cimg alt=\"Scala.js logo\" src=\"http://www.scala-js.org/assets/img/scala-js-logo.svg\" height=\"150\"/\u003e\n\u003c/a\u003e\n\n[Webpack](http://webpack.js.org/) loader for [Scala.js](https://www.scala-js.org/).  \nImport Scala.js code in a Webpack project, without having to set up a separate Scala build.\n\n\u003c/div\u003e\n\n[![Build Status](https://travis-ci.com/MaximeKjaer/scalajs-webpack-loader.svg?branch=master)](https://travis-ci.com/MaximeKjaer/scalajs-webpack-loader)\n[![npm version](https://img.shields.io/npm/v/scalajs-webpack-loader)](https://www.npmjs.com/package/scalajs-webpack-loader)\n[![Gitter](https://badges.gitter.im/scalajs-webpack-loader/community.svg)](https://gitter.im/scalajs-webpack-loader/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\nscalajs-webpack-loader is similar to [scalajs-bundler](https://github.com/scalacenter/scalajs-bundler) in that it is a tool that uses Webpack to bundle Scala.js code alongside JavaScript code. Use scalajs-bundler if your build tool is SBT, and use scalajs-webpack-loader if your build tool is Webpack.\n\nThe loader supports Scala.js 1.x. It should also work on Scala.js 0.6.15 – 0.6.33, but note that only 1.x is tested for and explicitly supported.\n\n## Installing\n\nInstall scalajs-webpack-loader as a dev-dependency of your NPM package by running:\n\n```console\n$ npm install --save-dev scalajs-webpack-loader\n```\n\nscalajs-webpack-loader currently requires at least Node v10.0. Check your version using:\n\n```console\n$ node -v\n```\n\n## Usage\n\n### Basic usage\n\nThis example assumes the following directory structure:\n\n```\n├── src/\n|   ├── js/\n|   |   └── index.js\n|   └── scala/\n|       ├── .sjsproject\n|       └── HelloWorld.scala\n├── webpack.config.js\n└── package.json\n```\n\nscalajs-webpack-loader allows you to import a Scala.js module into another Webpack module. A Scala.js module is a directory containing `*.scala` files, with an empty `.sjsproject` file at the root. Here, we can define `HelloWorld.scala` as follows:\n\n```scala\nimport scalajs.js.annotation._\n\n@JSExportTopLevel(\"HelloWorld\")\nobject HelloWorld {\n  @JSExport\n  def sayHello(): Unit = {\n    println(\"Hello world!\")\n  }\n}\n```\n\nYou can then import the Scala.js module in `index.js` as follows:\n\n```javascript\nimport { HelloWorld } from \"../scala/.sjsproject\";\n\nHelloWorld.sayHello();\n```\n\nYou should add scalajs-webpack-loader to your `webpack.config.js`:\n\n```javascript\nmodule.exports = {\n  // Configure entry and output paths:\n  entry: \"src/js/index.js\",\n  output: {\n    path: path.resolve(__dirname, \"dist\"),\n    filename: \"bundle.js\"\n  },\n  // ...\n  // Add scalajs-webpack-loader:\n  module: {\n    rules: [\n      {\n        test: /\\.sjsproject$/,\n        use: [\n          {\n            loader: \"scalajs-webpack-loader\",\n            options: {\n              // verbosity: \"warn\",\n              // mainMethod: \"Main.main\",\n              // etc. See \"Loader options\" below\n            }\n          }\n        ]\n      }\n    ]\n  }\n};\n```\n\nRun `npx webpack` to create the output bundle. The loader will download dependencies, compile the Scala.js code to the `target` folder, and bundle it with the JS module. Executing the output bundle in Node.js gives the following output:\n\n```console\n$ node dist/bundle.js\nHello world!\n```\n\n### Loader options\n\n| Option key            | Type                                                              | Default     | Description                                                           |\n| --------------------- | ----------------------------------------------------------------- | ----------- | --------------------------------------------------------------------- |\n| `mainMethod`          | string or undefined                                               | `undefined` | Execute the specified `main(Array[String])` method on startup         |\n| `verbosity`           | `\"trace\"`, `\"debug\"`, `\"info\"`, `\"warn\"`, `\"error\"` or `\"silent\"` | `\"info\"`    | Do not display log levels below specified verbosity                   |\n| `targetDirectory`     | string                                                            | `\"target\"`  | Target directory for intermediary Scala build artifacts               |\n| `scalaVersion`        | string                                                            | `\"2.13.1\"`  | Version of the Scala compiler                                         |\n| `scalaJSVersion`      | string                                                            | `\"1.0.0\"`   | Version of the Scala.js compiler                                      |\n| `libraryDependencies` | array of strings                                                  | `[]`        | List of Scala.js dependencies, e.g. `[\"com.lihaoyi:::upickle:0.9.9\"]` |\n| `scalacOptions`       | array of strings                                                  | `[]`        | List of [scalac options][scalac-options], e.g. `[\"-Xfatal-warnings\"]` |\n\n[scalac-options]: https://docs.scala-lang.org/overviews/compiler-options/index.html\n\nFor the `libraryDependencies` options, use the Mill format for dependencies. You can use [Scaladex](https://index.scala-lang.org/) to see what that looks like for your specific dependencies. Use `:::` to get the Scala.js artifact (e.g. `com.lihaoyi:::upickle:0.9.9`), and `::` for the Scala artifact (e.g. `org.scala-lang.modules::scala-async:0.10.0`).\n\n## Development\n\nTo develop the code in this repo, you will need to have `sbt` and `npm` installed on your system. Run `npm install` after cloning the repo to get all JS dependencies of this project.\n\nAll development commands can be run with NPM. Note that some of these commands depend on the `NODE_ENV` environment variable, which can either be set to `production` or `development`; if it isn't set, it's interpreted as `development`. Depending on the environment variable, some commands will execute in development (fast) mode or in production (slow, optimized) mode.\n\n| `npm run ...`               | Description                                                           |\n| --------------------------- | --------------------------------------------------------------------- |\n| `build`                     | Run a full build                                                      |\n| `build:scalajs`             | Build Scala.js sources in mode dictated by `NODE_ENV`                 |\n| `build:scalajs:production`  | Build Scala.js sources in production mode (`fullOptJS`)               |\n| `build:scalajs:development` | Build Scala.js sources in development mode (`fastOptJS`)              |\n| `build:bundle`              | Build final output bundle in mode dictated by `NODE_ENV`              |\n| `test`                      | Run all tests                                                         |\n| `test:package`              | Test that `package.json` is valid                                     |\n| `test:format:scala`         | Test formatting of Scala files with scalafmt                          |\n| `test:format:js`            | Test formatting of JS and config files                                |\n| `test:integration`          | Run integration tests                                                 |\n| `test:unit`                 | Run Scala.js unit tests                                               |\n| `fix`                       | Run all automatic fixes                                               |\n| `fix:format:scala`          | Run scalafmt fixes for all Scala files                                |\n| `fix:format:js`             | Run Prettier fixes for all JS and config files                        |\n| `clean`                     | Delete all build artifacts                                            |\n| `clean:scalajs`             | Delete Scala.js build artifacts                                       |\n| `clean:bundle`              | Clean Webpack's `dist/bundle.js`                                      |\n| `clean:fixtures`            | Clean local caches and build artifacts from integration test fixtures |\n\nRemember to build before testing.\n\nScalafmt commands try to run the CLI, and fall back to using SBT. If you run these commands frequently, you may want to install the [scalafmt CLI](https://scalameta.org/scalafmt/docs/installation.html#cli) for faster execution of these commands (`coursier install scalafmt` if you have [Coursier](https://get-coursier.io/) installed on your `PATH`).\n\nTo release a new version, run `npm version patch`, `npm version minor` or `npm version major`. Travis CI will automatically deploy the new version once the CI build passes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximekjaer%2Fscalajs-webpack-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximekjaer%2Fscalajs-webpack-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximekjaer%2Fscalajs-webpack-loader/lists"}